summaryrefslogtreecommitdiff
path: root/gerbonara/gerber/tests/panelize/test_utility.py
diff options
context:
space:
mode:
authorjaseg <git@jaseg.de>2021-06-13 20:33:19 +0200
committerjaseg <git@jaseg.de>2021-06-13 20:33:19 +0200
commitd0f836ecfadacbaea20fc6a3ceebd455e96e1307 (patch)
tree48b63dac21cf2849dbbf287947cb926081e0105e /gerbonara/gerber/tests/panelize/test_utility.py
parent7bebf9fe62dad33867ba6df1c0c611f8b313c549 (diff)
downloadgerbonara-d0f836ecfadacbaea20fc6a3ceebd455e96e1307.tar.gz
gerbonara-d0f836ecfadacbaea20fc6a3ceebd455e96e1307.tar.bz2
gerbonara-d0f836ecfadacbaea20fc6a3ceebd455e96e1307.zip
Port old pcb-tools-extension unit tests to pytest
Diffstat (limited to 'gerbonara/gerber/tests/panelize/test_utility.py')
-rw-r--r--gerbonara/gerber/tests/panelize/test_utility.py63
1 files changed, 63 insertions, 0 deletions
diff --git a/gerbonara/gerber/tests/panelize/test_utility.py b/gerbonara/gerber/tests/panelize/test_utility.py
new file mode 100644
index 0000000..b32af8b
--- /dev/null
+++ b/gerbonara/gerber/tests/panelize/test_utility.py
@@ -0,0 +1,63 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+# Copyright 2019 Hiroshi Murayama <opiopan@gmail.com>
+
+import unittest
+
+from ...panelize.utility import *
+from math import sqrt
+
+class TestUtility(unittest.TestCase):
+ def test_rotate(self):
+ x0, y0 = (10, 0)
+
+ x1, y1 = rotate(x0, y0, 60, (0, 0))
+ self.assertAlmostEqual(x1, 5)
+ self.assertAlmostEqual(y1, 10 * sqrt(3) / 2)
+
+ x1, y1 = rotate(x0, y0, 180, (5, 0))
+ self.assertAlmostEqual(x1, 0)
+ self.assertAlmostEqual(y1, 0)
+
+ x1, y1 = rotate(x0, y0, -90, (10, 5))
+ self.assertAlmostEqual(x1, 5)
+ self.assertAlmostEqual(y1, 5)
+
+ def test_is_equal_value(self):
+ a = 10.0001
+ b = 10.01
+
+ self.assertTrue(is_equal_value(a, b, 0.1))
+ self.assertTrue(is_equal_value(a, b, 0.01))
+ self.assertFalse(is_equal_value(a, b, 0.001))
+ self.assertFalse(is_equal_value(a, b))
+
+ self.assertTrue(is_equal_value(b, a, 0.1))
+ self.assertTrue(is_equal_value(b, a, 0.01))
+ self.assertFalse(is_equal_value(b, a, 0.001))
+ self.assertFalse(is_equal_value(b, a))
+
+ def test_is_equal_point(self):
+ p0 = (10.01, 5.001)
+ p1 = (10.0001, 5)
+ self.assertTrue(is_equal_point(p0, p1, 0.1))
+ self.assertTrue(is_equal_point(p0, p1, 0.01))
+ self.assertFalse(is_equal_point(p0, p1, 0.001))
+ self.assertFalse(is_equal_point(p0, p1))
+ self.assertTrue(is_equal_point(p1, p0, 0.1))
+ self.assertTrue(is_equal_point(p1, p0, 0.01))
+ self.assertFalse(is_equal_point(p1, p0, 0.001))
+ self.assertFalse(is_equal_point(p1, p0))
+
+ p0 = (5.001, 10.01)
+ p1 = (5, 10.0001)
+ self.assertTrue(is_equal_point(p0, p1, 0.1))
+ self.assertTrue(is_equal_point(p0, p1, 0.01))
+ self.assertFalse(is_equal_point(p0, p1, 0.001))
+ self.assertFalse(is_equal_point(p0, p1))
+ self.assertTrue(is_equal_point(p1, p0, 0.1))
+ self.assertTrue(is_equal_point(p1, p0, 0.01))
+ self.assertFalse(is_equal_point(p1, p0, 0.001))
+ self.assertFalse(is_equal_point(p1, p0))
+