From 695e3d9220be8773f6630bb5c512d122b8576742 Mon Sep 17 00:00:00 2001 From: Hamilton Kibbe Date: Sun, 28 Sep 2014 18:07:15 -0400 Subject: Added excellon support and refactored project --- gerber/tests/test_utils.py | 68 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 gerber/tests/test_utils.py (limited to 'gerber/tests/test_utils.py') diff --git a/gerber/tests/test_utils.py b/gerber/tests/test_utils.py new file mode 100644 index 0000000..50e2403 --- /dev/null +++ b/gerber/tests/test_utils.py @@ -0,0 +1,68 @@ +#! /usr/bin/env python +# -*- coding: utf-8 -*- + +# Author: Hamilton Kibbe + +from ..utils import decimal_string, parse_gerber_value, write_gerber_value + + +def test_zero_suppression(): + """ Test gerber value parser and writer handle zero suppression correctly. + """ + # Default format + format = (2, 5) + + # Test leading zero suppression + zero_suppression = 'leading' + test_cases = [('1', 0.00001), ('10', 0.0001), ('100', 0.001), + ('1000', 0.01), ('10000', 0.1), ('100000', 1.0),('1000000', 10.0), + ('-1', -0.00001), ('-10', -0.0001), ('-100', -0.001), + ('-1000', -0.01), ('-10000', -0.1), ('-100000', -1.0),('-1000000', -10.0),] + for string, value in test_cases: + assert(value == parse_gerber_value(string,format,zero_suppression)) + assert(string == write_gerber_value(value,format,zero_suppression)) + + # Test trailing zero suppression + zero_suppression = 'trailing' + test_cases = [('1', 10.0), ('01', 1.0), ('001', 0.1), ('0001', 0.01), + ('00001', 0.001), ('000001', 0.0001), ('0000001', 0.00001), + ('-1', -10.0), ('-01', -1.0), ('-001', -0.1), ('-0001', -0.01), + ('-00001', -0.001), ('-000001', -0.0001), ('-0000001', -0.00001)] + for string, value in test_cases: + assert(value == parse_gerber_value(string,format,zero_suppression)) + assert(string == write_gerber_value(value,format,zero_suppression)) + + + +def test_format(): + """ Test gerber value parser and writer handle format correctly + """ + zero_suppression = 'leading' + test_cases = [((2,7),'1',0.0000001), ((2,6),'1',0.000001), + ((2,5),'1',0.00001), ((2,4),'1',0.0001), ((2,3),'1',0.001), + ((2,2),'1',0.01), ((2,1),'1',0.1), ((2,7),'-1',-0.0000001), + ((2,6),'-1',-0.000001), ((2,5),'-1',-0.00001), ((2,4),'-1',-0.0001), + ((2,3),'-1',-0.001), ((2,2),'-1',-0.01), ((2,1),'-1',-0.1),] + for format, string, value in test_cases: + assert(value == parse_gerber_value(string,format,zero_suppression)) + assert(string == write_gerber_value(value,format,zero_suppression)) + + zero_suppression = 'trailing' + test_cases = [((6, 5), '1' , 100000.0), ((5, 5), '1', 10000.0), + ((4, 5), '1', 1000.0), ((3, 5), '1', 100.0),((2, 5), '1', 10.0), + ((1, 5), '1', 1.0), ((6, 5), '-1' , -100000.0), + ((5, 5), '-1', -10000.0), ((4, 5), '-1', -1000.0), + ((3, 5), '-1', -100.0),((2, 5), '-1', -10.0), ((1, 5), '-1', -1.0),] + for format, string, value in test_cases: + assert(value == parse_gerber_value(string,format,zero_suppression)) + assert(string == write_gerber_value(value,format,zero_suppression)) + + +def test_decimal_truncation(): + """ Test decimal string truncates value to the correct precision + """ + value = 1.123456789 + for x in range(10): + result = decimal_string(value, precision=x) + calculated = '1.' + ''.join(str(y) for y in range(1,x+1)) + assert(result == calculated) \ No newline at end of file -- cgit From af97dcf2a8200d9319e20d2789dbb0baa0611ba5 Mon Sep 17 00:00:00 2001 From: Hamilton Kibbe Date: Tue, 7 Oct 2014 22:44:08 -0400 Subject: fix excellon render --- gerber/tests/test_utils.py | 81 +++++++++++++++++++++++++++------------------- 1 file changed, 48 insertions(+), 33 deletions(-) (limited to 'gerber/tests/test_utils.py') diff --git a/gerber/tests/test_utils.py b/gerber/tests/test_utils.py index 50e2403..001a32f 100644 --- a/gerber/tests/test_utils.py +++ b/gerber/tests/test_utils.py @@ -3,6 +3,7 @@ # Author: Hamilton Kibbe +from .tests import assert_equal from ..utils import decimal_string, parse_gerber_value, write_gerber_value @@ -10,59 +11,73 @@ def test_zero_suppression(): """ Test gerber value parser and writer handle zero suppression correctly. """ # Default format - format = (2, 5) - + fmt = (2, 5) + # Test leading zero suppression zero_suppression = 'leading' test_cases = [('1', 0.00001), ('10', 0.0001), ('100', 0.001), - ('1000', 0.01), ('10000', 0.1), ('100000', 1.0),('1000000', 10.0), - ('-1', -0.00001), ('-10', -0.0001), ('-100', -0.001), - ('-1000', -0.01), ('-10000', -0.1), ('-100000', -1.0),('-1000000', -10.0),] + ('1000', 0.01), ('10000', 0.1), ('100000', 1.0), + ('1000000', 10.0), ('-1', -0.00001), ('-10', -0.0001), + ('-100', -0.001), ('-1000', -0.01), ('-10000', -0.1), + ('-100000', -1.0), ('-1000000', -10.0), ] for string, value in test_cases: - assert(value == parse_gerber_value(string,format,zero_suppression)) - assert(string == write_gerber_value(value,format,zero_suppression)) - + assert(value == parse_gerber_value(string, fmt, zero_suppression)) + assert(string == write_gerber_value(value, fmt, zero_suppression)) + # Test trailing zero suppression zero_suppression = 'trailing' test_cases = [('1', 10.0), ('01', 1.0), ('001', 0.1), ('0001', 0.01), - ('00001', 0.001), ('000001', 0.0001), ('0000001', 0.00001), - ('-1', -10.0), ('-01', -1.0), ('-001', -0.1), ('-0001', -0.01), - ('-00001', -0.001), ('-000001', -0.0001), ('-0000001', -0.00001)] + ('00001', 0.001), ('000001', 0.0001), + ('0000001', 0.00001), ('-1', -10.0), ('-01', -1.0), + ('-001', -0.1), ('-0001', -0.01), ('-00001', -0.001), + ('-000001', -0.0001), ('-0000001', -0.00001)] for string, value in test_cases: - assert(value == parse_gerber_value(string,format,zero_suppression)) - assert(string == write_gerber_value(value,format,zero_suppression)) - + assert(value == parse_gerber_value(string, fmt, zero_suppression)) + assert(string == write_gerber_value(value, fmt, zero_suppression)) def test_format(): """ Test gerber value parser and writer handle format correctly """ zero_suppression = 'leading' - test_cases = [((2,7),'1',0.0000001), ((2,6),'1',0.000001), - ((2,5),'1',0.00001), ((2,4),'1',0.0001), ((2,3),'1',0.001), - ((2,2),'1',0.01), ((2,1),'1',0.1), ((2,7),'-1',-0.0000001), - ((2,6),'-1',-0.000001), ((2,5),'-1',-0.00001), ((2,4),'-1',-0.0001), - ((2,3),'-1',-0.001), ((2,2),'-1',-0.01), ((2,1),'-1',-0.1),] - for format, string, value in test_cases: - assert(value == parse_gerber_value(string,format,zero_suppression)) - assert(string == write_gerber_value(value,format,zero_suppression)) - + test_cases = [((2, 7), '1', 0.0000001), ((2, 6), '1', 0.000001), + ((2, 5), '1', 0.00001), ((2, 4), '1', 0.0001), + ((2, 3), '1', 0.001), ((2, 2), '1', 0.01), + ((2, 1), '1', 0.1), ((2, 7), '-1', -0.0000001), + ((2, 6), '-1', -0.000001), ((2, 5), '-1', -0.00001), + ((2, 4), '-1', -0.0001), ((2, 3), '-1', -0.001), + ((2, 2), '-1', -0.01), ((2, 1), '-1', -0.1), ] + for fmt, string, value in test_cases: + assert(value == parse_gerber_value(string, fmt, zero_suppression)) + assert(string == write_gerber_value(value, fmt, zero_suppression)) + zero_suppression = 'trailing' - test_cases = [((6, 5), '1' , 100000.0), ((5, 5), '1', 10000.0), - ((4, 5), '1', 1000.0), ((3, 5), '1', 100.0),((2, 5), '1', 10.0), - ((1, 5), '1', 1.0), ((6, 5), '-1' , -100000.0), - ((5, 5), '-1', -10000.0), ((4, 5), '-1', -1000.0), - ((3, 5), '-1', -100.0),((2, 5), '-1', -10.0), ((1, 5), '-1', -1.0),] - for format, string, value in test_cases: - assert(value == parse_gerber_value(string,format,zero_suppression)) - assert(string == write_gerber_value(value,format,zero_suppression)) + test_cases = [((6, 5), '1', 100000.0), ((5, 5), '1', 10000.0), + ((4, 5), '1', 1000.0), ((3, 5), '1', 100.0), + ((2, 5), '1', 10.0), ((1, 5), '1', 1.0), + ((6, 5), '-1', -100000.0), ((5, 5), '-1', -10000.0), + ((4, 5), '-1', -1000.0), ((3, 5), '-1', -100.0), + ((2, 5), '-1', -10.0), ((1, 5), '-1', -1.0), ] + for fmt, string, value in test_cases: + assert(value == parse_gerber_value(string, fmt, zero_suppression)) + assert(string == write_gerber_value(value, fmt, zero_suppression)) def test_decimal_truncation(): - """ Test decimal string truncates value to the correct precision + """ Test decimal_string truncates value to the correct precision """ value = 1.123456789 for x in range(10): result = decimal_string(value, precision=x) calculated = '1.' + ''.join(str(y) for y in range(1,x+1)) - assert(result == calculated) \ No newline at end of file + assert(result == calculated) + + +def test_decimal_padding(): + """ Test decimal_string padding + """ + value = 1.123 + assert_equal(decimal_string(value, precision=3, padding=True), '1.123') + assert_equal(decimal_string(value, precision=4, padding=True), '1.1230') + assert_equal(decimal_string(value, precision=5, padding=True), '1.12300') + assert_equal(decimal_string(value, precision=6, padding=True), '1.123000') -- cgit