SailorEval / evaluation /tests /test_content_quality.py
QingchengChang's picture
Add SailorEval v1.3.4 benchmark data and evaluation suite
e12d99b verified
Raw History Blame Contribute Delete
3.74 kB
"""Regressions for evidenced content defects; no archive is needed to run these."""
import math
import re
import unittest
from evaluation.io import DATA,read_jsonl,task_specs
from evaluation.quality import degree_option_value,missing_case_material_errors
class ContentQualityTests(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.rows={row['id']:row for task in task_specs() for row in read_jsonl(DATA/task['path'])}
def correct(self,uid):
row=self.rows[uid]
return row['options'][row['answer']]
def number(self,uid):
return float(re.search(r'[+-]?\d+(?:\.\d+)?',self.correct(uid)).group())
def test_equivalent_degrees_without_collapsing_side_or_units(self):
self.assertEqual(degree_option_value('030°'),degree_option_value('30°'))
self.assertEqual(degree_option_value('033°.75'),degree_option_value('33.75°'))
self.assertNotEqual(degree_option_value('-30°'),degree_option_value('30°'))
for text in ['30° left','S30°W','30 m',"30°15'",'33.5°.75']:
self.assertIsNone(degree_option_value(text))
def test_missing_weather_instance_is_distinct_from_theory(self):
example=dict(question='On the surface weather chart, what wind occurred at that time?',media={})
self.assertTrue(missing_case_material_errors(example))
self.assertFalse(missing_case_material_errors(dict(example,media={'image':'map.png'})))
self.assertFalse(missing_case_material_errors(dict(example,context={'station_observations':'supplied'})))
self.assertFalse(missing_case_material_errors(dict(question='On a weather chart, what does a closed isobar mean?')))
def test_depth_datum_and_sounder_reference(self):
self.assertAlmostEqual(self.number('navigation_environment/0362'),8.7+.7-6)
self.assertAlmostEqual(self.number('navigation_environment/0488'),9.5+2.5+1)
for sid,draught in [('0134',10),('0716',4)]:
uid='navigation_environment/'+sid
self.assertIn('BELOW KEEL',self.rows[uid]['question'])
self.assertAlmostEqual(self.number(uid),21+draught)
def test_physical_moments_and_ship_weight_change(self):
self.assertAlmostEqual(self.number('ship_structure/1982'),(60800+28800)/16000)
self.assertAlmostEqual(self.number('ship_structure/0461'),round(796/6631,2))
self.assertAlmostEqual(self.number('ship_structure/1835'),9.8+(-300-100+600)/20/100)
heel=math.degrees(math.atan(.1/1.41))
self.assertAlmostEqual(self.number('ship_structure/1961'),round(heel,1))
def test_relative_bearings_have_declared_frame_and_unique_values(self):
for sid,expected in [('0183',(60-30)%360),('1937',(120+160)%360),('1737',(30-40)%360)]:
uid='navigation_environment/'+sid
self.assertEqual(degree_option_value(self.correct(uid)),expected)
values=[degree_option_value(v) for v in self.rows[uid]['options'].values()]
self.assertEqual(len(values),len(set(values)))
def test_missing_sources_excluded_without_deleting_chart_theory(self):
for uid in ['ship_structure/0029','ship_structure/1289','ship_structure/0808',
'navigation_environment/1427','navigation_environment/1582','navigation_environment/1279',
'navigation_environment/0452','navigation_environment/1039','navigation_environment/1386',
'navigation_environment/1869','navigation_environment/1990']:
self.assertNotIn(uid,self.rows)
for sid in ['0172','0407','0914','0915','1503','1614','1943','1987']:
self.assertIn('navigation_environment/'+sid,self.rows)
if __name__=='__main__':unittest.main()