From 7ddfa829d4157374b804666f20c8029078325d96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Montan=CC=83ana?= Date: Tue, 26 Apr 2022 00:43:27 +0200 Subject: [PATCH] Begin paircheck test 99% coverage --- benchmark/tests/PairCheck_test.py | 149 ++++++------------ benchmark/tests/test_files/paircheck.test | 4 + .../tests/test_files/paircheck_lose.test | 6 + benchmark/tests/test_files/paircheck_win.test | 6 + .../tests/test_files/paircheck_win_lose.test | 8 + 5 files changed, 70 insertions(+), 103 deletions(-) create mode 100644 benchmark/tests/test_files/paircheck.test create mode 100644 benchmark/tests/test_files/paircheck_lose.test create mode 100644 benchmark/tests/test_files/paircheck_win.test create mode 100644 benchmark/tests/test_files/paircheck_win_lose.test diff --git a/benchmark/tests/PairCheck_test.py b/benchmark/tests/PairCheck_test.py index 7ae1ae6..ecb5869 100644 --- a/benchmark/tests/PairCheck_test.py +++ b/benchmark/tests/PairCheck_test.py @@ -2,8 +2,7 @@ import os import unittest from io import StringIO from unittest.mock import patch -from ..Results import Summary -from ..Utils import Symbols +from ..Results import PairCheck class PairCheckTest(unittest.TestCase): @@ -11,110 +10,54 @@ class PairCheckTest(unittest.TestCase): os.chdir(os.path.dirname(os.path.abspath(__file__))) super().__init__(*args, **kwargs) - def test_summary_list_results_model(self): - report = Summary() - report.acquire() + def build_model( + self, + score="accuracy", + model1="STree", + model2="RandomForest", + win=False, + lose=False, + ): + return PairCheck(score, model1, model2, win, lose) + + def test_pair_check(self): + report = self.build_model(model1="ODTE", model2="STree") + report.compute() with patch("sys.stdout", new=StringIO()) as fake_out: - report.list_results(model="STree") + report.report() + computed = fake_out.getvalue() + with open(os.path.join("test_files", "PairCheck.test"), "r") as f: + expected = f.read() + self.assertEqual(computed, expected) + + def test_pair_check_win(self): + report = self.build_model(win=True) + report.compute() + with patch("sys.stdout", new=StringIO()) as fake_out: + report.report() + computed = fake_out.getvalue() + with open(os.path.join("test_files", "PairCheck_win.test"), "r") as f: + expected = f.read() + self.assertEqual(computed, expected) + + def test_pair_check_lose(self): + report = self.build_model(lose=True) + report.compute() + with patch("sys.stdout", new=StringIO()) as fake_out: + report.report() + computed = fake_out.getvalue() + with open(os.path.join("test_files", "PairCheck_lose.test"), "r") as f: + expected = f.read() + self.assertEqual(computed, expected) + + def test_pair_check_win_lose(self): + report = self.build_model(win=True, lose=True) + report.compute() + with patch("sys.stdout", new=StringIO()) as fake_out: + report.report() computed = fake_out.getvalue() with open( - os.path.join("test_files", "summary_list_model.test"), "r" + os.path.join("test_files", "PairCheck_win_lose.test"), "r" ) as f: expected = f.read() self.assertEqual(computed, expected) - - def test_summary_list_results_score(self): - report = Summary() - report.acquire() - with patch("sys.stdout", new=StringIO()) as fake_out: - report.list_results(score="accuracy") - computed = fake_out.getvalue() - with open( - os.path.join("test_files", "summary_list_score.test"), "r" - ) as f: - expected = f.read() - self.assertEqual(computed, expected) - - def test_summary_list_results_n(self): - report = Summary() - report.acquire() - with patch("sys.stdout", new=StringIO()) as fake_out: - report.list_results(score="accuracy", number=3) - computed = fake_out.getvalue() - with open(os.path.join("test_files", "summary_list_n.test"), "r") as f: - expected = f.read() - self.assertEqual(computed, expected) - - def test_summary_list_hiden(self): - report = Summary(hidden=True) - report.acquire() - with patch("sys.stdout", new=StringIO()) as fake_out: - report.list_results(score="accuracy") - computed = fake_out.getvalue() - with open( - os.path.join("test_files", "summary_list_hidden.test"), "r" - ) as f: - expected = f.read() - self.assertEqual(computed, expected) - - def test_show_result_no_title(self): - report = Summary() - report.acquire() - with patch("sys.stdout", new=StringIO()) as fake_out: - title = "" - best = report.best_result( - criterion="model", value="STree", score="accuracy" - ) - report.show_result(data=best, title=title) - computed = fake_out.getvalue() - with open( - os.path.join("test_files", "summary_show_results.test"), "r" - ) as f: - expected = f.read() - self.assertEqual(computed, expected) - - def test_show_result_title(self): - report = Summary() - report.acquire() - with patch("sys.stdout", new=StringIO()) as fake_out: - title = "**Title**" - best = report.best_result( - criterion="model", value="STree", score="accuracy" - ) - report.show_result(data=best, title=title) - computed = fake_out.getvalue() - with open( - os.path.join("test_files", "summary_show_results_title.test"), "r" - ) as f: - expected = f.read() - self.assertEqual(computed, expected) - - def test_show_result_no_data(self): - report = Summary() - report.acquire() - with patch("sys.stdout", new=StringIO()) as fake_out: - title = "**Test**" - report.show_result(data={}, title=title) - computed = fake_out.getvalue() - expected = f"** **Test** has No data **\n" - self.assertEqual(computed, expected) - - def test_best_results_datasets(self): - report = Summary() - report.acquire() - computed = report.best_results_datasets() - expected = { - "balance-scale": ( - 0.83616, - {}, - "results_accuracy_RandomForest_iMac27_2022-01-14_12:39:30_0.json", - "Test default paramters with RandomForest", - ), - "balloons": ( - 0.5566666666666668, - {"max_features": "auto", "splitter": "mutual"}, - "results_accuracy_STree_macbook-pro_2021-11-01_19:17:07_0.json", - "default B", - ), - } - self.assertSequenceEqual(computed, expected) diff --git a/benchmark/tests/test_files/paircheck.test b/benchmark/tests/test_files/paircheck.test new file mode 100644 index 0000000..1c9af47 --- /dev/null +++ b/benchmark/tests/test_files/paircheck.test @@ -0,0 +1,4 @@ +Model File Score Win Tie Lose +==================== ====================================================================== ========== === === ==== +ODTE results_accuracy_ODTE_Galgo_2022-04-20_10:52:20_0.json 0.04341 +STree results_accuracy_STree_iMac27_2021-09-30_11:42:07_0.json 0.04544  0  0  2 diff --git a/benchmark/tests/test_files/paircheck_lose.test b/benchmark/tests/test_files/paircheck_lose.test new file mode 100644 index 0000000..c1b3174 --- /dev/null +++ b/benchmark/tests/test_files/paircheck_lose.test @@ -0,0 +1,6 @@ +Model File Score Win Tie Lose +==================== ====================================================================== ========== === === ==== +STree results_accuracy_STree_iMac27_2021-09-30_11:42:07_0.json 0.04544 +RandomForest results_accuracy_RandomForest_iMac27_2022-01-14_12:39:30_0.json 0.03627  2  0  0 +losers: +[] diff --git a/benchmark/tests/test_files/paircheck_win.test b/benchmark/tests/test_files/paircheck_win.test new file mode 100644 index 0000000..a544a35 --- /dev/null +++ b/benchmark/tests/test_files/paircheck_win.test @@ -0,0 +1,6 @@ +Model File Score Win Tie Lose +==================== ====================================================================== ========== === === ==== +STree results_accuracy_STree_iMac27_2021-09-30_11:42:07_0.json 0.04544 +RandomForest results_accuracy_RandomForest_iMac27_2022-01-14_12:39:30_0.json 0.03627  2  0  0 +Winners: +['balance-scale', 'balloons'] diff --git a/benchmark/tests/test_files/paircheck_win_lose.test b/benchmark/tests/test_files/paircheck_win_lose.test new file mode 100644 index 0000000..7d7b511 --- /dev/null +++ b/benchmark/tests/test_files/paircheck_win_lose.test @@ -0,0 +1,8 @@ +Model File Score Win Tie Lose +==================== ====================================================================== ========== === === ==== +STree results_accuracy_STree_iMac27_2021-09-30_11:42:07_0.json 0.04544 +RandomForest results_accuracy_RandomForest_iMac27_2022-01-14_12:39:30_0.json 0.03627  2  0  0 +Winners: +['balance-scale', 'balloons'] +losers: +[]