Skip to content

Commit 75973d6

Browse files
committed
Add validation of original name and test
1 parent 651cfe0 commit 75973d6

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/axelrod_fortran/player.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,10 @@ def original_name(self):
4747

4848
@original_name.setter
4949
def original_name(self, value):
50-
# TODO Validate the value against list of known fortran functions
51-
self.__original_name = value
50+
if value in characteristics:
51+
self.__original_name = value
52+
else:
53+
raise ValueError(f'{value} is not a valid Fortran function')
5254

5355
@property
5456
def original_function(self):

tests/test_player.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from ctypes import c_int, c_float, POINTER
77

88
import itertools
9+
import pytest
910

1011
C, D = Action.C, Action.D
1112

@@ -20,6 +21,8 @@ def test_init():
2021
POINTER(c_int), POINTER(c_int), POINTER(c_int), POINTER(c_int),
2122
POINTER(c_float))
2223
assert player.original_function.restype == c_int
24+
with pytest.raises(ValueError):
25+
player = Player('test')
2326

2427

2528
def test_matches():

0 commit comments

Comments
 (0)