Example #1
0
    def test_from_dict(self):
        """From_dict sets the dictionary values as instance attributes."""
        # Setup
        parameters = {
            'index': 0,
            'L': 2,
            'R': 5,
            'name': 'clayton',
            'theta': 1.5,
            'D': [1, 3],
            'U': None,
            'likelihood': None,
            'neighbors': [1],
            'parents': None,
            'tau': None
        }

        # Run
        edge = Edge.from_dict(parameters)

        # Check
        assert edge.index == 0
        assert edge.L == 2
        assert edge.R == 5
        assert edge.name == 'clayton'
        assert edge.theta == 1.5
        assert edge.D == [1, 3]
        assert not edge.U
        assert not edge.parents
        assert edge.neighbors == [1]
Example #2
0
    def test_valid_serialization(self):
        # Setup
        instance = Edge(0, 2, 5, 'clayton', 1.5)

        # Run
        result = Edge.from_dict(instance.to_dict())

        # Check
        assert instance.to_dict() == result.to_dict()
Example #3
0
    def test_from_dict(self):
        """From_dict sets the dictionary values as instance attributes."""
        # Setup
        parameters = {
            'L':
            2,
            'R':
            5,
            'name':
            'clayton',
            'theta':
            1.5,
            'D': [1, 3],
            'U':
            None,
            'likelihood':
            None,
            'neighbors': [{
                'L': 3,
                'R': 4,
                'name': 'gumbel',
                'theta': 0.4,
                'D': [2, 5],
                'U': None,
                'likelihood': None,
                'neighbors': None,
                'parents': None,
                'tau': None
            }],
            'parents':
            None,
            'tau':
            None
        }

        # Run
        edge = Edge.from_dict(parameters)

        # Check
        assert edge.L == 2
        assert edge.R == 5
        assert edge.name == 'clayton'
        assert edge.theta == 1.5
        assert edge.D == [1, 3]
        assert not edge.U
        assert not edge.parents
        assert len(edge.neighbors) == 1
        assert edge.neighbors[0].L == 3
        assert edge.neighbors[0].R == 4
        assert edge.neighbors[0].name == 'gumbel'
        assert edge.neighbors[0].D == [2, 5]
        assert not edge.neighbors[0].parents