Esempio n. 1
0
    def test_invalid_classes(self):
        """Checks for invalid classes"""

        matrix = tm.TransitionMatrix(PRNG, CLASSES)

        with pytest.raises(KeyError):
            matrix.p("x", 1)
        with pytest.raises(KeyError):
            matrix.p(34, 1)
Esempio n. 2
0
    def test_initial_probabilty(self):
        """Tests initial probability"""

        matrix = tm.TransitionMatrix(PRNG, CLASSES)

        # Everything should be zero
        for class_1 in CLASSES:
            for class_2 in CLASSES:
                assert matrix.get_weight(class_1, class_2) == 0
                assert matrix.p(class_1, class_2) == 0
                assert matrix.p(class_2, class_1) == 0
Esempio n. 3
0
    def test_invalid_weights(self):
        """Checks for invalid weights"""

        matrix = tm.TransitionMatrix(PRNG, CLASSES)

        with pytest.raises(ValueError):
            matrix.set_weight(1, 1, -50)

        with pytest.raises(TypeError):
            matrix.set_weight(1, 1, "watermelon")
        with pytest.raises(TypeError):
            matrix.set_weight(1, 1, matrix)
Esempio n. 4
0
    def test_resampling_one_item(self):
        """Ensure the sampling always returns the one item it can"""

        matrix = tm.TransitionMatrix(PRNG, CLASSES)

        # Add some weights to certain transitions
        matrix.set_weight(1, 1, 1)
        matrix.set_weight(2, 3, 1)
        matrix.set_weight(3, 4, 22)
        matrix.set_weight(4, 1, 237827.2223)

        for _ in range(100):
            assert matrix.get_transition(1) == 1
            assert matrix.get_transition(2) == 3
            assert matrix.get_transition(3) == 4
            assert matrix.get_transition(4) == 1
Esempio n. 5
0
    def test_simple_probabilty(self):
        """Tests calculation of probabilities"""

        matrix = tm.TransitionMatrix(PRNG, CLASSES)

        # Add some weights to certain transitions
        matrix.set_weight(1, 1, 1)
        matrix.set_weight(1, 2, 1)
        matrix.set_weight(2, 1, 5)
        matrix.set_weight(2, 2, 5)

        # Check probabilities
        assert matrix.p(1, 2) == 0.5
        assert matrix.p(1, 1) == 0.5
        assert matrix.p(2, 1) == 0.5
        assert matrix.p(2, 1) == 0.5
Esempio n. 6
0
    def test_one_path(self):
        """Tests calculation of probabilities"""

        matrix = tm.TransitionMatrix(PRNG, CLASSES)

        # Add some weights to certain transitions
        matrix.set_weight(1, 1, 1)
        matrix.set_weight(2, 2, 1)
        matrix.set_weight(3, 3, 22)
        matrix.set_weight(4, 4, 237827.2223)

        # Check probabilities
        assert matrix.p(1, 1) == 1
        assert matrix.p(2, 2) == 1
        assert matrix.p(3, 3) == 1
        assert matrix.p(4, 4) == 1

        assert matrix.p(2, 1) == 0
        assert matrix.p(1, 2) == 0