Esempio n. 1
0
def test_Recode_To_Binary_absent_state_but_keep_zero():
    orig = {'Maori': '0', 'Dutch': '2', 'Latin': '1'}
    states, recoded = _recode_to_binary(orig, keep_zero=True)
    assert states == ('0', '1', '2')
    assert recoded['Maori'] == '100', recoded
    assert recoded['Dutch'] == '001', recoded
    assert recoded['Latin'] == '010', recoded
Esempio n. 2
0
 def test_error_on_integer(self):
     orig = {'Maori': 1, 'Dutch': '1', 'Latin': '1'}
     with self.assertRaises(ValueError):
         recoded = _recode_to_binary(orig)
Esempio n. 3
0
 def test_polymorphic_states(self):
     orig = {'Maori': '1,3', 'Dutch': '2', 'Latin': '3'}
     recoded = _recode_to_binary(orig)
     assert recoded['Maori'] == '101', recoded
     assert recoded['Dutch'] == '010', recoded
     assert recoded['Latin'] == '001', recoded
Esempio n. 4
0
 def test_noncontiguous_states(self):
     orig = {'Maori': '1', 'Dutch': '5', 'Latin': '9'}
     recoded = _recode_to_binary(orig)
     assert recoded['Maori'] == '100'
     assert recoded['Dutch'] == '010'
     assert recoded['Latin'] == '001'
Esempio n. 5
0
 def test_gap_state(self):
     orig = {'Maori': '-', 'Dutch': '2', 'Latin': '1'}
     recoded = _recode_to_binary(orig)
     assert recoded['Maori'] == '00'
     assert recoded['Dutch'] == '01'
     assert recoded['Latin'] == '10'
Esempio n. 6
0
 def test_absent_state_but_keep_zero(self):
     orig = {'Maori': '0', 'Dutch': '2', 'Latin': '1'}
     recoded = _recode_to_binary(orig, keep_zero=True)
     assert recoded['Maori'] == '100', recoded
     assert recoded['Dutch'] == '001', recoded
     assert recoded['Latin'] == '010', recoded
Esempio n. 7
0
 def test_absent_state(self):
     orig = {'Maori': '0', 'Dutch': '2', 'Latin': '1'}
     recoded = _recode_to_binary(orig)
     assert recoded['Maori'] == '00', recoded
     assert recoded['Dutch'] == '01', recoded
     assert recoded['Latin'] == '10', recoded
Esempio n. 8
0
 def test_one(self):
     orig = {'Maori': '1', 'Dutch': '1', 'Latin': '1'}
     recoded = _recode_to_binary(orig)
     assert recoded['Maori'] == '1'
     assert recoded['Dutch'] == '1'
     assert recoded['Latin'] == '1'
Esempio n. 9
0
 def test_error_on_badvalue(self):
     orig = {'Maori': None, 'Dutch': '1', 'Latin': '1'}
     with self.assertRaises(ValueError):
         _recode_to_binary(orig)
Esempio n. 10
0
def test_Recode_To_Binary_error_on_integer():
    orig = {'Maori': 1, 'Dutch': '1', 'Latin': '1'}
    with pytest.raises(ValueError):
        _recode_to_binary(orig)
Esempio n. 11
0
def test_recode_to_binary(input, expected):
    states, recoded = _recode_to_binary(
        dict(zip(['Maori', 'Dutch', 'Latin'], input)))
    assert states == expected[0]
    assert recoded == dict(zip(['Maori', 'Dutch', 'Latin'], expected[1]))
Esempio n. 12
0
 def test_error_on_badvalue(self):
     orig = {'Maori': None, 'Dutch': '1', 'Latin': '1'}
     with self.assertRaises(ValueError):
         _recode_to_binary(orig)