Skip to content

Commit f0dc7ea

Browse files
committed
implemented basic unit tests
1 parent 6c99a1f commit f0dc7ea

File tree

2 files changed

+72
-3
lines changed

2 files changed

+72
-3
lines changed

bashplotlib/scatterplot.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def get_scale(series, is_y=False, steps=20):
3131
return scaled_series
3232

3333

34-
def _plot_scatter(xs, ys, size, pch, colour, title, cs, x_title, y_title):
34+
def _plot_scatter(xs, ys, size, pch, title, cs, x_title, y_title):
3535
plotted = set()
3636
graph = ""
3737

@@ -63,7 +63,7 @@ def _plot_scatter(xs, ys, size, pch, colour, title, cs, x_title, y_title):
6363
point = "-"
6464
graph += point + " "
6565
graph += " |\n"
66-
graph += " +" + "-" * (2 * (len(get_scale(xs, False, size)) + 2) - 2) + "+"
66+
graph += " +" + "-" * (2 * (len(get_scale(xs, False, size)) + 2) - 2) + "+\n"
6767
graph += " " + x_title
6868
return graph
6969

@@ -99,7 +99,7 @@ def plot_scatter(f, xs, ys, size, pch, colour, title, x_title, y_title):
9999
with open(ys) as fh:
100100
ys = [float(str(row).strip()) for row in fh]
101101

102-
graph = _plot_scatter(xs, ys, size, pch, colour, title, cs, x_title, y_title)
102+
graph = _plot_scatter(xs, ys, size, pch, title, cs, x_title, y_title)
103103
print(graph)
104104

105105

test.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# test.py
2+
from bashplotlib.scatterplot import _plot_scatter
3+
import unittest
4+
5+
class TestScatterPlot(unittest.TestCase):
6+
def test_no_points(self):
7+
self.assertEqual(_plot_scatter([], [], 10, "x",
8+
"My Test Graph", "default", "My X Axis", "My Y Axis"),
9+
""" +------------------------+\n | My Test Graph |
10+
+------------------------+
11+
+------------------------+
12+
M | | |
13+
y | | |
14+
| | |
15+
Y | | |
16+
| | |
17+
A | - - - - - o - - - - - |
18+
x | | |
19+
i | | |
20+
s | | |
21+
| | |
22+
| | |
23+
+------------------------+
24+
My X Axis""")
25+
26+
def test_points(self):
27+
self.assertEqual(_plot_scatter([-10, -3, 20,30], [-10, 6, 20,-2], 10, "*",
28+
"Points!", "default", "Something x", "Another y"),
29+
""" +--------------------------+\n | Points! |
30+
+--------------------------+
31+
+--------------------------+
32+
A | | * |
33+
n | | |
34+
o | | |
35+
t | | |
36+
h | | |
37+
e | * | |
38+
r | | |
39+
| - - - o - - - - - - - - |
40+
y | | |
41+
| | * |
42+
| | |
43+
| * | |
44+
+--------------------------+
45+
Something x""")
46+
47+
def test_points_on_axes(self):
48+
self.assertEqual(_plot_scatter([0, -10, 0, 20,0], [0, 0, 6, 0,-2], 10, "#",
49+
"Points!", "default", "x", "y"),
50+
""" +--------------------------+\n | Points! |
51+
+--------------------------+
52+
+--------------------------+
53+
y | # |
54+
| | |
55+
| | |
56+
| | |
57+
| | |
58+
| | |
59+
| | |
60+
| | |
61+
| # - - - # - - - - - - # |
62+
| | |
63+
| | |
64+
| # |
65+
+--------------------------+
66+
x""")
67+
68+
if __name__ == "__main__":
69+
unittest.main()

0 commit comments

Comments
 (0)