mirror of
https://github.com/Doctorado-ML/benchmark.git
synced 2025-08-17 00:15:55 +00:00
Begin paircheck test 99% coverage
This commit is contained in:
@@ -2,8 +2,7 @@ import os
|
|||||||
import unittest
|
import unittest
|
||||||
from io import StringIO
|
from io import StringIO
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
from ..Results import Summary
|
from ..Results import PairCheck
|
||||||
from ..Utils import Symbols
|
|
||||||
|
|
||||||
|
|
||||||
class PairCheckTest(unittest.TestCase):
|
class PairCheckTest(unittest.TestCase):
|
||||||
@@ -11,110 +10,54 @@ class PairCheckTest(unittest.TestCase):
|
|||||||
os.chdir(os.path.dirname(os.path.abspath(__file__)))
|
os.chdir(os.path.dirname(os.path.abspath(__file__)))
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
def test_summary_list_results_model(self):
|
def build_model(
|
||||||
report = Summary()
|
self,
|
||||||
report.acquire()
|
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:
|
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()
|
computed = fake_out.getvalue()
|
||||||
with open(
|
with open(
|
||||||
os.path.join("test_files", "summary_list_model.test"), "r"
|
os.path.join("test_files", "PairCheck_win_lose.test"), "r"
|
||||||
) as f:
|
) as f:
|
||||||
expected = f.read()
|
expected = f.read()
|
||||||
self.assertEqual(computed, expected)
|
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)
|
|
||||||
|
4
benchmark/tests/test_files/paircheck.test
Normal file
4
benchmark/tests/test_files/paircheck.test
Normal file
@@ -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 [92m 0 [93m 0 [91m 2
|
6
benchmark/tests/test_files/paircheck_lose.test
Normal file
6
benchmark/tests/test_files/paircheck_lose.test
Normal file
@@ -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 [92m 2 [93m 0 [91m 0
|
||||||
|
[91mlosers:
|
||||||
|
[]
|
6
benchmark/tests/test_files/paircheck_win.test
Normal file
6
benchmark/tests/test_files/paircheck_win.test
Normal file
@@ -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 [92m 2 [93m 0 [91m 0
|
||||||
|
[92mWinners:
|
||||||
|
['balance-scale', 'balloons']
|
8
benchmark/tests/test_files/paircheck_win_lose.test
Normal file
8
benchmark/tests/test_files/paircheck_win_lose.test
Normal file
@@ -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 [92m 2 [93m 0 [91m 0
|
||||||
|
[92mWinners:
|
||||||
|
['balance-scale', 'balloons']
|
||||||
|
[91mlosers:
|
||||||
|
[]
|
Reference in New Issue
Block a user