forked from UKGovernmentBEIS/inspect_ai
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improved metrics value_to_float string conversion (UKGovernmentBEIS#196)
Co-authored-by: aisi-inspect <[email protected]>
- Loading branch information
Showing
3 changed files
with
54 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from inspect_ai.scorer import CORRECT, PARTIAL, value_to_float | ||
|
||
|
||
def test_value_to_float_numbers(): | ||
fn = value_to_float() | ||
assert fn(1) == 1.0 | ||
assert fn(0.5) == 0.5 | ||
assert fn(True) == 1.0 | ||
assert fn(False) == 0 | ||
|
||
|
||
def test_value_to_float_strings(): | ||
fn = value_to_float() | ||
assert fn("1.0") == 1.0 | ||
assert fn("0.5") == 0.5 | ||
assert fn("0") == 0 | ||
assert fn("yes") == 1.0 | ||
assert fn("No") == 0.0 | ||
assert fn(CORRECT) == 1.0 | ||
assert fn(PARTIAL) == 0.5 | ||
|
||
|
||
def test_value_to_float_custom(): | ||
fn = value_to_float(correct="correct", incorrect="incorrect") | ||
assert fn("correct") == 1.0 | ||
assert fn("incorrect") == 0 | ||
|
||
|
||
def test_value_to_float_invalid(): | ||
fn = value_to_float() | ||
assert fn("foo") == 0.0 |