def test_RVFunctions_from_partition(): d = dit.Distribution(['00', '01', '10', '11'], [1 / 4] * 4) bf = dit.RVFunctions(d) partition = (('00', '11'), ('01', '10')) d = dit.insert_rvf(d, bf.from_partition(partition)) outcomes = ('000', '011', '101', '110') assert_equal(d.outcomes, outcomes)
def test_RVFunctions_from_mapping1(): d = dit.Distribution(['00', '01', '10', '11'], [1 / 4] * 4) bf = dit.RVFunctions(d) mapping = {'00': '0', '01': '1', '10': '1', '11': '0'} d = dit.insert_rvf(d, bf.from_mapping(mapping)) outcomes = ('000', '011', '101', '110') assert_equal(d.outcomes, outcomes)
def test_RVFunctions_from_mapping2(): d = dit.Distribution([(0, 0), (0, 1), (1, 0), (1, 1)], [1 / 4] * 4) bf = dit.RVFunctions(d) mapping = {(0, 0): 0, (0, 1): 1, (1, 0): 1, (1, 1): 0} d = dit.insert_rvf(d, bf.from_mapping(mapping, force=True)) outcomes = ((0, 0, 0), (0, 1, 1), (1, 0, 1), (1, 1, 0)) assert_equal(d.outcomes, outcomes)
def test_rvfunctions1(): # Smoke test with strings d = dit.Distribution(['00', '01', '10', '11'], [1 / 4] * 4) bf = dit.RVFunctions(d) d = dit.insert_rvf(d, bf.xor([0, 1])) d = dit.insert_rvf(d, bf.xor([1, 2])) assert_equal(d.outcomes, ('0000', '0110', '1011', '1101'))
def test_rvfunctions2(): # Smoke test with int tuples d = dit.Distribution([(0,0), (0,1), (1,0), (1,1)], [1/4]*4) bf = dit.RVFunctions(d) d = dit.insert_rvf(d, bf.xor([0,1])) d = dit.insert_rvf(d, bf.xor([1,2])) assert d.outcomes == ((0,0,0,0), (0,1,1,0), (1,0,1,1), (1,1,0,1))
def test_rvfunctions_toolarge(): letters = 'abcd' outcomes = itertools.product(letters, repeat=3) outcomes = list(map(''.join, outcomes)) d = dit.Distribution(outcomes, [1 / 64] * 64, validate=False) rvf = dit.RVFunctions(d) partition = [(d.outcomes[i], ) for i in range(len(d))] assert_raises(NotImplementedError, rvf.from_partition, partition)
def test_rvfunctions_ints(): d = dit.uniform_distribution(2, 2) rvf = dit.RVFunctions(d) partition = [(d.outcomes[i], ) for i in range(len(d))] mapping = rvf.from_partition(partition) d2 = dit.insert_rvf(d, mapping) outcomes = ((0, 0, 0), (0, 1, 1), (1, 0, 2), (1, 1, 3)) assert_equal(d2.outcomes, outcomes)
def test_rvfunctions3(): # Smoke test strings with from_hexes outcomes = ['000', '001', '010', '011', '100', '101', '110', '111'] pmf = [1 / 8] * 8 d = dit.Distribution(outcomes, pmf) bf = dit.RVFunctions(d) d = dit.insert_rvf(d, bf.from_hexes('27')) outcomes = ('0000', '0010', '0101', '0110', '1000', '1010', '1100', '1111') assert_equal(d.outcomes, outcomes)
def test_rvfunctions4(): # Smoke test int tuples from_hexes outcomes = ['000', '001', '010', '011', '100', '101', '110', '111'] outcomes = [tuple(map(int, o)) for o in outcomes] pmf = [1 / 8] * 8 d = dit.Distribution(outcomes, pmf) bf = dit.RVFunctions(d) d = dit.insert_rvf(d, bf.from_hexes('27')) outcomes = ('0000', '0010', '0101', '0110', '1000', '1010', '1100', '1111') outcomes = tuple(tuple(map(int, o)) for o in outcomes) assert_equal(d.outcomes, outcomes)
def test_rvfunctions_scalardist(): d = dit.ScalarDistribution(range(5), [1 / 5] * 5) with pytest.raises(ditException): dit.RVFunctions(d)