summaryrefslogtreecommitdiff
path: root/gerber/tests
diff options
context:
space:
mode:
Diffstat (limited to 'gerber/tests')
-rw-r--r--gerber/tests/test_primitives.py85
-rw-r--r--gerber/tests/tests.py5
2 files changed, 88 insertions, 2 deletions
diff --git a/gerber/tests/test_primitives.py b/gerber/tests/test_primitives.py
new file mode 100644
index 0000000..29036b4
--- /dev/null
+++ b/gerber/tests/test_primitives.py
@@ -0,0 +1,85 @@
+#! /usr/bin/env python
+# -*- coding: utf-8 -*-
+
+# Author: Hamilton Kibbe <ham@hamiltonkib.be>
+from ..primitives import *
+from tests import *
+
+
+
+def test_line_angle():
+ """ Test Line primitive angle calculation
+ """
+ cases = [((0, 0), (1, 0), math.radians(0)),
+ ((0, 0), (1, 1), math.radians(45)),
+ ((0, 0), (0, 1), math.radians(90)),
+ ((0, 0), (-1, 1), math.radians(135)),
+ ((0, 0), (-1, 0), math.radians(180)),
+ ((0, 0), (-1, -1), math.radians(225)),
+ ((0, 0), (0, -1), math.radians(270)),
+ ((0, 0), (1, -1), math.radians(315)),]
+ for start, end, expected in cases:
+ l = Line(start, end, 0)
+ line_angle = (l.angle + 2 * math.pi) % (2 * math.pi)
+ assert_almost_equal(line_angle, expected)
+
+def test_line_bounds():
+ """ Test Line primitive bounding box calculation
+ """
+ cases = [((0, 0), (1, 1), ((0, 1), (0, 1))),
+ ((-1, -1), (1, 1), ((-1, 1), (-1, 1))),
+ ((1, 1), (-1, -1), ((-1, 1), (-1, 1))),
+ ((-1, 1), (1, -1), ((-1, 1), (-1, 1))),]
+ for start, end, expected in cases:
+ l = Line(start, end, 0)
+ assert_equal(l.bounding_box, expected)
+
+def test_arc_radius():
+ """ Test Arc primitive radius calculation
+ """
+ cases = [((-3, 4), (5, 0), (0, 0), 5),
+ ((0, 1), (1, 0), (0, 0), 1),]
+
+ for start, end, center, radius in cases:
+ a = Arc(start, end, center, 'clockwise', 0)
+ assert_equal(a.radius, radius)
+
+
+def test_arc_sweep_angle():
+ """ Test Arc primitive sweep angle calculation
+ """
+ cases = [((1, 0), (0, 1), (0, 0), 'counterclockwise', math.radians(90)),
+ ((1, 0), (0, 1), (0, 0), 'clockwise', math.radians(270)),
+ ((1, 0), (-1, 0), (0, 0), 'clockwise', math.radians(180)),
+ ((1, 0), (-1, 0), (0, 0), 'counterclockwise', math.radians(180)),]
+
+ for start, end, center, direction, sweep in cases:
+ a = Arc(start, end, center, direction, 0)
+ assert_equal(a.sweep_angle, sweep)
+
+
+def test_arc_bounds():
+ """ Test Arc primitive bounding box calculation
+ """
+ cases = [((1, 0), (0, 1), (0, 0), 'clockwise', ((-1, 1), (-1, 1))),
+ ((1, 0), (0, 1), (0, 0), 'counterclockwise', ((0, 1), (0, 1))),
+ #TODO: ADD MORE TEST CASES HERE
+ ]
+
+ for start, end, center, direction, bounds in cases:
+ a = Arc(start, end, center, direction, 0)
+ assert_equal(a.bounding_box, bounds)
+
+def test_circle_radius():
+ """ Test Circle primitive radius calculation
+ """
+ c = Circle((1, 1), 2)
+ assert_equal(c.radius, 1)
+
+def test_circle_bounds():
+ """ Test Circle bounding box calculation
+ """
+ c = Circle((1, 1), 2)
+ assert_equal(c.bounding_box, ((0, 2), (0, 2)))
+
+
diff --git a/gerber/tests/tests.py b/gerber/tests/tests.py
index 29b7899..222eea3 100644
--- a/gerber/tests/tests.py
+++ b/gerber/tests/tests.py
@@ -7,6 +7,7 @@ from nose.tools import assert_in
from nose.tools import assert_not_in
from nose.tools import assert_equal
from nose.tools import assert_not_equal
+from nose.tools import assert_almost_equal
from nose.tools import assert_true
from nose.tools import assert_false
from nose.tools import assert_raises
@@ -14,5 +15,5 @@ from nose.tools import raises
from nose import with_setup
__all__ = ['assert_in', 'assert_not_in', 'assert_equal', 'assert_not_equal',
- 'assert_true', 'assert_false', 'assert_raises', 'raises',
- 'with_setup' ]
+ 'assert_almost_equal', 'assert_true', 'assert_false',
+ 'assert_raises', 'raises', 'with_setup' ]