Skip to content

Commit

Permalink
Add DiscreteConditional unit test for markdown printing
Browse files Browse the repository at this point in the history
  • Loading branch information
varunagrawal committed Dec 25, 2021
1 parent 2422e11 commit ffa73a4
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions python/gtsam/tests/test_DiscreteConditional.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
"""
GTSAM Copyright 2010-2021, Georgia Tech Research Corporation,
Atlanta, Georgia 30332-0415
All Rights Reserved
See LICENSE for the license information
Unit tests for Discrete Conditionals.
Author: Varun Agrawal
"""

# pylint: disable=no-name-in-module, invalid-name

import unittest

from gtsam import DiscreteConditional, DiscreteKeys
from gtsam.utils.test_case import GtsamTestCase


class TestDiscreteConditional(GtsamTestCase):
"""Tests for Discrete Conditionals."""
def test_markdown(self):
"""Test whether the _repr_markdown_ method."""

A = (2, 2)
B = (1, 2)
C = (0, 3)
parents = DiscreteKeys()
parents.push_back(B)
parents.push_back(C)

conditional = DiscreteConditional(A, parents,
"0/1 1/3 1/1 3/1 0/1 1/0")
expected = \
" $P(A|B,C)$:\n" \
"|B|C|0|1|\n" \
"|:-:|:-:|:-:|:-:|\n" \
"|0|0|0|1|\n" \
"|0|1|0.25|0.75|\n" \
"|0|2|0.5|0.5|\n" \
"|1|0|0.75|0.25|\n" \
"|1|1|0|1|\n" \
"|1|2|1|0|\n"

def formatter(x: int):
names = ["C", "B", "A"]
return names[x]

actual = conditional._repr_markdown_(formatter)
self.assertEqual(actual, expected)


if __name__ == "__main__":
unittest.main()

0 comments on commit ffa73a4

Please sign in to comment.