Spaces:
Running
Running
MilesCranmer
commited on
Commit
•
44b5271
1
Parent(s):
c5cd4bb
Refactor latex table tests
Browse files- test/test.py +19 -17
test/test.py
CHANGED
@@ -498,6 +498,16 @@ class TestMiscellaneous(unittest.TestCase):
|
|
498 |
|
499 |
|
500 |
class TestLaTeXTable(unittest.TestCase):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
501 |
def create_true_latex(self, middle_part, include_score=False):
|
502 |
if include_score:
|
503 |
true_latex_table_str = r"""
|
@@ -528,17 +538,9 @@ class TestLaTeXTable(unittest.TestCase):
|
|
528 |
return true_latex_table_str.strip()
|
529 |
|
530 |
def test_simple_table(self):
|
531 |
-
|
532 |
-
|
533 |
-
equation=["x0", "cos(x0)", "x0 + x1 - cos(x1 * x0)"],
|
534 |
-
loss=[1.052, 0.02315, 1.12347e-15],
|
535 |
-
complexity=[1, 2, 8],
|
536 |
-
)
|
537 |
)
|
538 |
-
model = manually_create_model(equations)
|
539 |
-
|
540 |
-
# Regular table:
|
541 |
-
latex_table_str = model.latex_table(columns=["equation", "complexity", "loss"])
|
542 |
middle_part = r"""
|
543 |
$x_{0}$ & $1$ & $1.05$ \\
|
544 |
$\cos{\left(x_{0} \right)}$ & $2$ & $0.0232$ \\
|
@@ -547,8 +549,8 @@ class TestLaTeXTable(unittest.TestCase):
|
|
547 |
true_latex_table_str = self.create_true_latex(middle_part)
|
548 |
self.assertEqual(latex_table_str, true_latex_table_str)
|
549 |
|
550 |
-
|
551 |
-
latex_table_str = model.latex_table(
|
552 |
precision=5, columns=["equation", "complexity", "loss"]
|
553 |
)
|
554 |
middle_part = r"""
|
@@ -557,10 +559,10 @@ class TestLaTeXTable(unittest.TestCase):
|
|
557 |
$x_{0} + x_{1} - \cos{\left(x_{0} x_{1} \right)}$ & $8$ & $1.1235 \cdot 10^{-15}$ \\
|
558 |
"""
|
559 |
true_latex_table_str = self.create_true_latex(middle_part)
|
560 |
-
self.assertEqual(latex_table_str,
|
561 |
|
562 |
-
|
563 |
-
latex_table_str = model.latex_table()
|
564 |
middle_part = r"""
|
565 |
$x_{0}$ & $1$ & $1.05$ & $0.0$ \\
|
566 |
$\cos{\left(x_{0} \right)}$ & $2$ & $0.0232$ & $3.82$ \\
|
@@ -569,8 +571,8 @@ class TestLaTeXTable(unittest.TestCase):
|
|
569 |
true_latex_table_str = self.create_true_latex(middle_part, include_score=True)
|
570 |
self.assertEqual(latex_table_str, true_latex_table_str)
|
571 |
|
572 |
-
|
573 |
-
latex_table_str = model.latex_table(
|
574 |
indices=[2], columns=["equation", "complexity", "loss"]
|
575 |
)
|
576 |
middle_part = r"""
|
|
|
498 |
|
499 |
|
500 |
class TestLaTeXTable(unittest.TestCase):
|
501 |
+
def setUp(self):
|
502 |
+
equations = pd.DataFrame(
|
503 |
+
dict(
|
504 |
+
equation=["x0", "cos(x0)", "x0 + x1 - cos(x1 * x0)"],
|
505 |
+
loss=[1.052, 0.02315, 1.12347e-15],
|
506 |
+
complexity=[1, 2, 8],
|
507 |
+
)
|
508 |
+
)
|
509 |
+
self.model = manually_create_model(equations)
|
510 |
+
|
511 |
def create_true_latex(self, middle_part, include_score=False):
|
512 |
if include_score:
|
513 |
true_latex_table_str = r"""
|
|
|
538 |
return true_latex_table_str.strip()
|
539 |
|
540 |
def test_simple_table(self):
|
541 |
+
latex_table_str = self.model.latex_table(
|
542 |
+
columns=["equation", "complexity", "loss"]
|
|
|
|
|
|
|
|
|
543 |
)
|
|
|
|
|
|
|
|
|
544 |
middle_part = r"""
|
545 |
$x_{0}$ & $1$ & $1.05$ \\
|
546 |
$\cos{\left(x_{0} \right)}$ & $2$ & $0.0232$ \\
|
|
|
549 |
true_latex_table_str = self.create_true_latex(middle_part)
|
550 |
self.assertEqual(latex_table_str, true_latex_table_str)
|
551 |
|
552 |
+
def test_other_precision(self):
|
553 |
+
latex_table_str = self.model.latex_table(
|
554 |
precision=5, columns=["equation", "complexity", "loss"]
|
555 |
)
|
556 |
middle_part = r"""
|
|
|
559 |
$x_{0} + x_{1} - \cos{\left(x_{0} x_{1} \right)}$ & $8$ & $1.1235 \cdot 10^{-15}$ \\
|
560 |
"""
|
561 |
true_latex_table_str = self.create_true_latex(middle_part)
|
562 |
+
self.assertEqual(latex_table_str, true_latex_table_str)
|
563 |
|
564 |
+
def test_include_score(self):
|
565 |
+
latex_table_str = self.model.latex_table()
|
566 |
middle_part = r"""
|
567 |
$x_{0}$ & $1$ & $1.05$ & $0.0$ \\
|
568 |
$\cos{\left(x_{0} \right)}$ & $2$ & $0.0232$ & $3.82$ \\
|
|
|
571 |
true_latex_table_str = self.create_true_latex(middle_part, include_score=True)
|
572 |
self.assertEqual(latex_table_str, true_latex_table_str)
|
573 |
|
574 |
+
def test_last_equation(self):
|
575 |
+
latex_table_str = self.model.latex_table(
|
576 |
indices=[2], columns=["equation", "complexity", "loss"]
|
577 |
)
|
578 |
middle_part = r"""
|