File size: 985 Bytes
87cc7f2 | 1 2 3 4 5 6 7 8 9 10 11 12 | import unittest,sys,torch
from pathlib import Path
sys.path.insert(0,str(Path(__file__).resolve().parents[1]/'src'))
from long_protocol import *
class ProtocolTests(unittest.TestCase):
def test_prompt(self):self.assertEqual(build_prompt('Q'),r'Q'+'\n'+r'Please reason step by step, and put your final answer within \boxed{}.')
def test_penalty_excludes_prompt_and_counts_presence_once(self):
scores=torch.zeros((1,8));ids=torch.tensor([[3,4,2,2,5]]);o=GeneratedPresencePenalty(2,1.5)(ids,scores);self.assertEqual(o[0,2],-1.5);self.assertEqual(o[0,5],-1.5);self.assertEqual(o[0,3],0);self.assertEqual(o[0,4],0)
def test_extract_strict_reasoning_and_boxes(self):
self.assertEqual(strict_extract(r'\boxed{1} </think> Answer \boxed{\frac{1}{2}}'),r'\frac{1}{2}');self.assertIsNone(strict_extract(r'\boxed{2} then \boxed{'));self.assertEqual(strict_extract('x \\boxed 5$'), '5');self.assertIsNone(strict_extract('The answer is 3'))
if __name__=='__main__':unittest.main()
|