Repository: pgmpy/pgmpy

Issue:
Don't print the complete Tabular CPD when the table is too large
Try with this CPD to see what happens when table is too large:

``` python3
meeting_cpd = TabularCPD('meetingtype', 2, [[0.75], [0.25]])

bottle_cpd = TabularCPD('levelbottle', 5, [[0.2], [0.2], [0.2], [0.2], [0.2]])

obstacle_cpd = TabularCPD('obstacle', 8, [[0.42372881], [0.084745763], [0.16949153], [0.042372881], [0.16949153], [0.042372881], [0.042372881], [0.025423729]])

glass_cpd = TabularCPD('levelglass', 5, [[0.1], [0.3], [0.3], [0.2], [0.1]])

desirable_cpd = TabularCPD('desirable', 2, [[0.65, 0.8], [0.35, 0.2]], evidence=['meetingtype'], evidence_card=[2])

grasp_cpd = TabularCPD('grasp', 4, [[0, 0.016, 0.13, 0.3, 0.3, 0, 0.025, 0.2, 0.45, 0.5, 0, 0.025, 0.2, 0.45, 0.5, 0, 0.05, 0.4, 0.9, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.016, 0.1, 0.28, 0.3, 0, 0.025, 0.15, 0.425, 0.5, 0, 0.025, 0.15, 0.425, 0.5, 0, 0.05, 0.3, 0.85, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.006, 0.06, 0.273, 0.3, 0, 0.01, 0.1, 0.41, 0.5, 0, 0.01, 0.1, 0.41, 0.5, 0, 0.02, 0.2, 0.82, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.06, 0.26, 0.316, 0, 0, 0.1, 0.4, 0.475, 0, 0, 0.1, 0.4, 0.475, 0, 0, 0.2, 0.8, 0.95, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]],
                       evidence=['levelglass', 'obstacle', 'levelbottle', 'desirable'], evidence_card=[5, 8, 5, 2])
```


Discussion:
ankurankan: @FelipeGiro Thanks for the PR. The tests are failing because of formatting. If you run `black .` from the pgmpy dir, it should fix it.
codecov[bot]: # [Codecov](https://codecov.io/gh/pgmpy/pgmpy/pull/1441?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pgmpy) Report
> Merging [#1441](https://codecov.io/gh/pgmpy/pgmpy/pull/1441?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pgmpy) (a51da81) into [dev](https://codecov.io/gh/pgmpy/pgmpy/commit/44d518744fbf2d6ed5cdd6b140dcb92a9825f555?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pgmpy) (44d5187) will **decrease** coverage by `0.70%`.
> The diff coverage is `96.87%`.

[![Impacted file tree graph](https://codecov.io/gh/pgmpy/pgmpy/pull/1441/graphs/tree.svg?width=650&height=150&src=pr&token=UaJMCdHaEF&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pgmpy)](https://codecov.io/gh/pgmpy/pgmpy/pull/1441?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pgmpy)

```diff
@@            Coverage Diff             @@
##              dev    #1441      +/-   ##
==========================================
- Coverage   94.41%   93.70%   -0.71%     
==========================================
  Files         138      138              
  Lines       15482    15643     +161     
==========================================
+ Hits        14617    14659      +42     
- Misses        865      984     +119     
```


| [Impacted Files](https://codecov.io/gh/pgmpy/pgmpy/pull/1441?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pgmpy) | Coverage Δ | |
|---|---|---|
| [...py/tests/test\_factors/test\_discrete/test\_Factor.py](https://codecov.io/gh/pgmpy/pgmpy/pull/1441/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pgmpy#diff-cGdtcHkvdGVzdHMvdGVzdF9mYWN0b3JzL3Rlc3RfZGlzY3JldGUvdGVzdF9GYWN0b3IucHk=) | `99.70% <90.90%> (-0.15%)` | :arrow_down: |
| [pgmpy/factors/discrete/CPD.py](https://codecov.io/gh/pgmpy/pgmpy/pull/1441/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pgmpy#diff-cGdtcHkvZmFjdG9ycy9kaXNjcmV0ZS9DUEQucHk=) | `93.63% <100.00%> (+11.27%)` | :arrow_up: |
| [pgmpy/readwrite/XMLBeliefNetwork.py](https://codecov.io/gh/pgmpy/pgmpy/pull/1441/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pgmpy#diff-cGdtcHkvcmVhZHdyaXRlL1hNTEJlbGllZk5ldHdvcmsucHk=) | `53.62% <0.00%> (-39.14%)` | :arrow_down: |
| [...gmpy/tests/test\_readwrite/test\_XMLBeliefNetwork.py](https://codecov.io/gh/pgmpy/pgmpy/pull/1441/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pgmpy#diff-cGdtcHkvdGVzdHMvdGVzdF9yZWFkd3JpdGUvdGVzdF9YTUxCZWxpZWZOZXR3b3JrLnB5) | `75.40% <0.00%> (-18.86%)` | :arrow_down: |
| [pgmpy/readwrite/PomdpX.py](https://codecov.io/gh/pgmpy/pgmpy/pull/1441/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pgmpy#diff-cGdtcHkvcmVhZHdyaXRlL1BvbWRwWC5weQ==) | `86.62% <0.00%> (-10.37%)` | :arrow_down: |
| [pgmpy/tests/test\_readwrite/test\_PomdpX.py](https://codecov.io/gh/pgmpy/pgmpy/pull/1441/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pgmpy#diff-cGdtcHkvdGVzdHMvdGVzdF9yZWFkd3JpdGUvdGVzdF9Qb21kcFgucHk=) | `83.68% <0.00%> (-9.22%)` | :arrow_down: |
| [pgmpy/base/DAG.py](https://codecov.io/gh/pgmpy/pgmpy/pull/1441/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pgmpy#diff-cGdtcHkvYmFzZS9EQUcucHk=) | `92.33% <0.00%> (-2.10%)` | :arrow_down: |
| [pgmpy/estimators/MmhcEstimator.py](https://codecov.io/gh/pgmpy/pgmpy/pull/1441/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pgmpy#diff-cGdtcHkvZXN0aW1hdG9ycy9NbWhjRXN0aW1hdG9yLnB5) | `98.11% <0.00%> (-1.89%)` | :arrow_down: |
| [pgmpy/models/DynamicBayesianNetwork.py](https://codecov.io/gh/pgmpy/pgmpy/pull/1441/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pgmpy#diff-cGdtcHkvbW9kZWxzL0R5bmFtaWNCYXllc2lhbk5ldHdvcmsucHk=) | `93.11% <0.00%> (-0.59%)` | :arrow_down: |
| [pgmpy/models/BayesianNetwork.py](https://codecov.io/gh/pgmpy/pgmpy/pull/1441/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pgmpy#diff-cGdtcHkvbW9kZWxzL0JheWVzaWFuTmV0d29yay5weQ==) | `94.93% <0.00%> (ø)` | |
| ... and [7 more](https://codecov.io/gh/pgmpy/pgmpy/pull/1441/diff?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pgmpy) | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pgmpy/pgmpy/pull/1441?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pgmpy).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pgmpy)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/pgmpy/pgmpy/pull/1441?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pgmpy). Last update [44d5187...a51da81](https://codecov.io/gh/pgmpy/pgmpy/pull/1441?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pgmpy). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pgmpy).

ankurankan: @FelipeGiro Thanks again for the PR. This has been a long-standing issue. But I think you have accidentally committed a couple of binary files too: `pgmpy/.DS_Store` and `pgmpy/tests/.DS_Store`. Both seem to have been added in this commit: https://github.com/pgmpy/pgmpy/pull/1441/commits/999941b7b6b29762db75bee1e08242490e721103. If you could revert that commit, I think this PR should be good to go. 
FelipeGiro: I am glad to help. In my doctoral research I use quite often graphical models, perhaps I can contribute more. Thanks for your support @ankurankan 

Patch:
diff --git a/pgmpy/factors/discrete/CPD.py b/pgmpy/factors/discrete/CPD.py
index ca456a23..65dd6c8e 100644
--- a/pgmpy/factors/discrete/CPD.py
+++ b/pgmpy/factors/discrete/CPD.py
@@ -9,6 +9,8 @@ import numpy as np
 from pgmpy.factors.discrete import DiscreteFactor
 from pgmpy.extern import tabulate
 
+from shutil import get_terminal_size
+
 
 class TabularCPD(DiscreteFactor):
     """
@@ -183,8 +185,8 @@ class TabularCPD(DiscreteFactor):
 
     def _make_table_str(self, tablefmt="fancy_grid", print_state_names=True):
         headers_list = []
-        # build column headers
 
+        # Build column headers
         evidence = self.variables[1:]
         evidence_card = self.cardinality[1:]
         if evidence:
@@ -225,6 +227,44 @@ class TabularCPD(DiscreteFactor):
         ).tolist()
         # No support for multi-headers in tabulate
         cdf_str = tabulate(headers_list + labeled_rows, tablefmt=tablefmt)
+
+        cdf_str = self._truncate_strtable(cdf_str)
+
+        return cdf_str
+
+    def _truncate_strtable(self, cdf_str):
+        terminal_width, terminal_height = get_terminal_size()
+
+        list_rows_str = cdf_str.split("\n")
+
+        table_width, table_height = len(list_rows_str[0]), len(list_rows_str)
+
+        colstr_i = np.array(
+            [pos for pos, char in enumerate(list_rows_str[0]) if char == "+"]
+        )
+
+        if table_width > terminal_width:
+            half_width = terminal_width // 2 - 3
+
+            left_i = colstr_i[colstr_i < half_width][-1]
+            right_i = colstr_i[(table_width - colstr_i) < half_width][0]
+
+            new_cdf_str = []
+            for temp_row_str in list_rows_str:
+                left = temp_row_str[: left_i + 1]
+                right = temp_row_str[right_i:]
+                if temp_row_str[left_i] == "+":
+                    joiner = "-----"
+                else:
+                    joiner = " ... "
+                new_cdf_str.append(left + joiner + right)
+
+            cdf_str = "\n".join(new_cdf_str)
+
+        # TODO: vertical limitator
+        # if table_height > terminal_height:
+        #     half_height = terminal_height // 2
+
         return cdf_str
 
     def copy(self):


Test patch:
diff --git a/pgmpy/tests/test_factors/test_discrete/test_Factor.py b/pgmpy/tests/test_factors/test_discrete/test_Factor.py
index b261fb56..89573857 100644
--- a/pgmpy/tests/test_factors/test_discrete/test_Factor.py
+++ b/pgmpy/tests/test_factors/test_discrete/test_Factor.py
@@ -15,6 +15,8 @@ from pgmpy.models import BayesianNetwork
 from pgmpy.models import MarkovNetwork
 from pgmpy.utils import get_example_model
 
+from shutil import get_terminal_size
+
 
 class TestFactorInit(unittest.TestCase):
     def test_class_init(self):
@@ -1108,6 +1110,1635 @@ class TestTabularCPDInit(unittest.TestCase):
             [5, 6],
         )
 
+    def test_too_wide_cdp_table(self):
+        terminal_width, terminal_height = get_terminal_size()
+
+        grasp_cpd = TabularCPD(
+            "grasp",
+            4,
+            [
+                [
+                    0,
+                    0.016,
+                    0.13,
+                    0.3,
+                    0.3,
+                    0,
+                    0.025,
+                    0.2,
+                    0.45,
+                    0.5,
+                    0,
+                    0.025,
+                    0.2,
+                    0.45,
+                    0.5,
+                    0,
+                    0.05,
+                    0.4,
+                    0.9,
+                    1,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0.016,
+                    0.1,
+                    0.28,
+                    0.3,
+                    0,
+                    0.025,
+                    0.15,
+                    0.425,
+                    0.5,
+                    0,
+                    0.025,
+                    0.15,
+                    0.425,
+                    0.5,
+                    0,
+                    0.05,
+                    0.3,
+                    0.85,
+                    1,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0.006,
+                    0.06,
+                    0.273,
+                    0.3,
+                    0,
+                    0.01,
+                    0.1,
+                    0.41,
+                    0.5,
+                    0,
+                    0.01,
+                    0.1,
+                    0.41,
+                    0.5,
+                    0,
+                    0.02,
+                    0.2,
+                    0.82,
+                    1,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0.06,
+                    0.26,
+                    0.316,
+                    0,
+                    0,
+                    0.1,
+                    0.4,
+                    0.475,
+                    0,
+                    0,
+                    0.1,
+                    0.4,
+                    0.475,
+                    0,
+                    0,
+                    0.2,
+                    0.8,
+                    0.95,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                ],
+                [
+                    0,
+                    0.017,
+                    0.13,
+                    0.3,
+                    0.3,
+                    0,
+                    0.025,
+                    0.2,
+                    0.45,
+                    0.5,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0.025,
+                    0.2,
+                    0.45,
+                    0.5,
+                    0,
+                    0.05,
+                    0.4,
+                    0.9,
+                    1,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0.017,
+                    0.1,
+                    0.28,
+                    0.3,
+                    0,
+                    0.025,
+                    0.15,
+                    0.425,
+                    0.5,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0.025,
+                    0.15,
+                    0.425,
+                    0.5,
+                    0,
+                    0.05,
+                    0.3,
+                    0.85,
+                    1,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0.007,
+                    0.07,
+                    0.273,
+                    0.3,
+                    0,
+                    0.01,
+                    0.1,
+                    0.41,
+                    0.5,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0.01,
+                    0.1,
+                    0.41,
+                    0.5,
+                    0,
+                    0.02,
+                    0.2,
+                    0.82,
+                    1,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0.07,
+                    0.27,
+                    0.317,
+                    0,
+                    0,
+                    0.1,
+                    0.4,
+                    0.475,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0.1,
+                    0.4,
+                    0.475,
+                    0,
+                    0,
+                    0.2,
+                    0.8,
+                    0.95,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                ],
+                [
+                    0,
+                    0.017,
+                    0.14,
+                    0.3,
+                    0.4,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0.025,
+                    0.2,
+                    0.45,
+                    0.5,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0.025,
+                    0.2,
+                    0.45,
+                    0.5,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0.05,
+                    0.4,
+                    0.9,
+                    1,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0.017,
+                    0.1,
+                    0.29,
+                    0.4,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0.025,
+                    0.15,
+                    0.425,
+                    0.5,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0.025,
+                    0.15,
+                    0.425,
+                    0.5,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0.05,
+                    0.3,
+                    0.85,
+                    1,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0.007,
+                    0.07000000000000001,
+                    0.274,
+                    0.4,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0.01,
+                    0.1,
+                    0.41,
+                    0.5,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0.01,
+                    0.1,
+                    0.41,
+                    0.5,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0.02,
+                    0.2,
+                    0.82,
+                    1,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0.07000000000000001,
+                    0.27,
+                    0.317,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0.1,
+                    0.4,
+                    0.475,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0.1,
+                    0.4,
+                    0.475,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0.2,
+                    0.8,
+                    0.95,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                    0,
+                ],
+                [
+                    1,
+                    0.95,
+                    0.6,
+                    0.1,
+                    0,
+                    1,
+                    0.95,
+                    0.6,
+                    0.1,
+                    0,
+                    1,
+                    0.95,
+                    0.6,
+                    0.1,
+                    0,
+                    1,
+                    0.95,
+                    0.6,
+                    0.1,
+                    0,
+                    1,
+                    0.95,
+                    0.6,
+                    0.1,
+                    0,
+                    1,
+                    0.95,
+                    0.6,
+                    0.1,
+                    0,
+                    1,
+                    0.95,
+                    0.6,
+                    0.1,
+                    0,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    0.95,
+                    0.7,
+                    0.15,
+                    0,
+                    1,
+                    0.95,
+                    0.7,
+                    0.15,
+                    0,
+                    1,
+                    0.95,
+                    0.7,
+                    0.15,
+                    0,
+                    1,
+                    0.95,
+                    0.7,
+                    0.15,
+                    0,
+                    1,
+                    0.95,
+                    0.7,
+                    0.15,
+                    0,
+                    1,
+                    0.95,
+                    0.7,
+                    0.15,
+                    0,
+                    1,
+                    0.95,
+                    0.7,
+                    0.15,
+                    0,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    0.98,
+                    0.8,
+                    0.18,
+                    0,
+                    1,
+                    0.98,
+                    0.8,
+                    0.18,
+                    0,
+                    1,
+                    0.98,
+                    0.8,
+                    0.18,
+                    0,
+                    1,
+                    0.98,
+                    0.8,
+                    0.18,
+                    0,
+                    1,
+                    0.98,
+                    0.8,
+                    0.18,
+                    0,
+                    1,
+                    0.98,
+                    0.8,
+                    0.18,
+                    0,
+                    1,
+                    0.98,
+                    0.8,
+                    0.18,
+                    0,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    0.8,
+                    0.2,
+                    0.05,
+                    1,
+                    1,
+                    0.8,
+                    0.2,
+                    0.05,
+                    1,
+                    1,
+                    0.8,
+                    0.2,
+                    0.05,
+                    1,
+                    1,
+                    0.8,
+                    0.2,
+                    0.05,
+                    1,
+                    1,
+                    0.8,
+                    0.2,
+                    0.05,
+                    1,
+                    1,
+                    0.8,
+                    0.2,
+                    0.05,
+                    1,
+                    1,
+                    0.8,
+                    0.2,
+                    0.05,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                    1,
+                ],
+            ],
+            evidence=["levelglass", "obstacle", "levelbottle", "desirable"],
+            evidence_card=[5, 8, 5, 2],
+        )
+
+        cdf_str = grasp_cpd._make_table_str(tablefmt="grid")
+        terminal_width, terminal_height = get_terminal_size()
+        list_rows_str = cdf_str.split("\n")
+        table_width, table_length = len(list_rows_str[0]), len(list_rows_str)
+
+        # TODO: test table hight
+
+        self.assertGreater(terminal_width, table_width)
+
 
 class TestTabularCPDMethods(unittest.TestCase):
     def setUp(self):
@@ -1875,3 +3506,6 @@ class TestJointProbabilityDistributionMethods(unittest.TestCase):
 #     def tearDown(self):
 #         del self.rule_cpd_without_rules
 #
+
+if __name__ == "__main__":
+    unittest.main()