|
| 1 | +"""Tests for IFEval constraint verifiers in open_instruct.if_functions. |
| 2 | +
|
| 3 | +Covers regression fixes from PRs #1615 / #1646 (validate_choice operand |
| 4 | +direction) and #1646 (validate_frequency_capital_words "around" tolerance). |
| 5 | +""" |
| 6 | + |
| 7 | +import unittest |
| 8 | + |
| 9 | +from parameterized import parameterized |
| 10 | + |
| 11 | +from open_instruct import if_functions |
| 12 | + |
| 13 | + |
| 14 | +class TestValidateChoice(unittest.TestCase): |
| 15 | + @parameterized.expand( |
| 16 | + [ |
| 17 | + ("option_in_text", "I believe the answer is B", ["A", "B", "C", "D"], True), |
| 18 | + ("option_appears", "I choose red", ["red", "blue"], True), |
| 19 | + ("no_option_present", "I choose green", ["red", "blue"], False), |
| 20 | + ("exact_match", "red", ["red", "blue"], True), |
| 21 | + ] |
| 22 | + ) |
| 23 | + def test_validate_choice(self, _name, text, options, expected): |
| 24 | + self.assertEqual(if_functions.validate_choice(text, options), expected) |
| 25 | + |
| 26 | + |
| 27 | +class TestValidateFrequencyCapitalWords(unittest.TestCase): |
| 28 | + @parameterized.expand( |
| 29 | + [ |
| 30 | + ("around_exact", "AAA BBB CCC DDD EEE", 5, "around", True), |
| 31 | + ("around_off_by_one_low", "AAA BBB CCC DDD", 5, "around", True), |
| 32 | + ("around_off_by_one_high", "AAA BBB CCC DDD EEE FFF", 5, "around", True), |
| 33 | + ("around_far_off", "AAA BBB", 5, "around", False), |
| 34 | + ("at_least_satisfied", "AAA BBB CCC", 2, "at least", True), |
| 35 | + ("at_most_violated", "AAA BBB CCC DDD", 2, "at most", False), |
| 36 | + ] |
| 37 | + ) |
| 38 | + def test_validate_frequency_capital_words(self, _name, text, n, quantifier, expected): |
| 39 | + self.assertEqual(if_functions.validate_frequency_capital_words(text, n, quantifier), expected) |
| 40 | + |
| 41 | + |
| 42 | +if __name__ == "__main__": |
| 43 | + unittest.main() |
0 commit comments