first commit

This commit is contained in:
Senad Uka
2017-11-07 09:23:57 +01:00
commit 0eee92660a
356 changed files with 747259 additions and 0 deletions

0
test/models/__init__.py Normal file
View File

View File

@@ -0,0 +1,132 @@
import unittest
from numpy import array
from nose.tools import eq_
from numpy.testing import assert_almost_equal, assert_array_almost_equal
from helix.models.coordinate import Coordinate
class CoordinateTest(unittest.TestCase):
def test_equality(self):
a = Coordinate(0, 0, 0)
b = Coordinate(0, 0, 0)
assert a == b
def test_equality_x(self):
a = Coordinate(0, 0, 0)
b = Coordinate(1, 0, 0)
assert a != b
b = Coordinate(1e-9, 0, 0)
assert a == b
def test_equality_y(self):
a = Coordinate(0, 0, 0)
b = Coordinate(0, 1, 0)
assert a != b
b = Coordinate(0, 1e-7, 0)
assert a == b
def test_equality_rotation(self):
a = Coordinate(0, 0, 0)
b = Coordinate(0, 0, 1)
assert a != b
b = Coordinate(0, 0, 5e-7)
assert a == b
def test_subtraction(self):
a = Coordinate(3, 4, 0)
b = Coordinate(6, 2, 0)
eq_(a - b, Coordinate(-3, 2, 0))
def test_subtraction_maintains_rotation(self):
a = Coordinate(3, 4, 0.2)
b = Coordinate(6, 2, 0.2)
eq_(a - b, Coordinate(-3, 2, 0.2))
def test_subtraction_different_rotations_throws(self):
a = Coordinate(3, 4, 0)
b = Coordinate(6, 2, 0.2)
with self.assertRaises(ValueError) as context:
a - b
assert context.exception
def test_scale(self):
eq_(Coordinate(4, 6).scale(0.75, 0.6666667), Coordinate(3, 4))
def test_abs(self):
eq_(abs(Coordinate(1, 0, 0)), 1)
eq_(abs(Coordinate(3, 4, 0)), 5)
def test_less_than_identical(self):
a = Coordinate(0, 0, 0)
b = Coordinate(0, 0, 0)
assert not a < b
assert not b < a
def test_less_than_x_value(self):
a = Coordinate(0, 0, 0)
c = Coordinate(1, 0, 0)
assert a < c
assert not c < a
def test_less_than_y_value(self):
a = Coordinate(0, 0, 0)
c = Coordinate(1, 0, 0)
d = Coordinate(0, 1, 0)
assert a < d
assert not d < a
assert c < d
assert not d < c
def test_less_than_along_x_access(self):
c = Coordinate(1, 0, 0)
d = Coordinate(0, 1, 0)
e = Coordinate(2, 0, 0)
assert c < e
assert e < d
def test_less_than_diagonal(self):
d = Coordinate(0, 1, 0)
e = Coordinate(2, 0, 0)
f = Coordinate(1, 1, 0)
assert d < f
assert e < f
def test_computes_length(self):
a = Coordinate(29875.258, -61792.862, 2.534306)
b = Coordinate(29787.104, -61796.764, 2.534306)
assert_almost_equal(a.length(), 68635.915, 3)
assert_almost_equal(b.length(), 68601.105, 3)
def test_arrays_almost_equal_works(self):
value = array([
Coordinate(1.233, 3.444, 0)
])
expected = array([
Coordinate(1.234, 3.444, 0)
])
assert_array_almost_equal(value, expected, decimal=3)
def test_repr(self):
eq_(str(Coordinate(1.233, 3.444, 0)), '{"rotation": 0, "x": 1.233, "y": 3.444}')
def test_rotate(self):
a = Coordinate(10, 10, 0)
b = Coordinate(20, 5, 90)
eq_(a.rotate(), Coordinate(10, 10, 0))
eq_(b.rotate(), Coordinate(-5, 20, 0))

View File

@@ -0,0 +1,27 @@
import unittest
from nose.tools import eq_
from helix.models.coordinate import Coordinate
from helix.models.dxf.graph_node import GraphNode
from helix.models.panel import Panel
from helix.models.dxf.graph_node_store import GraphNodeStore
class GraphNodeStoreTest(unittest.TestCase):
def setUp(self):
self.subject = GraphNodeStore()
def test_find_coordinate(self):
node_one = GraphNode(Panel(coordinate=Coordinate(2, 104, rotation=1.07)), 0, 0)
node_two = GraphNode(Panel(coordinate=Coordinate(2, 105, rotation=1.07)), 0, 0)
node_three = GraphNode(Panel(coordinate=Coordinate(3, 104, rotation=1.07)), 0, 0)
self.subject.add_node(node_one)
self.subject.add_node(node_two)
self.subject.add_node(node_three)
eq_(self.subject.find_coordinate(Coordinate(2, 104, rotation=1.07)), node_one)
eq_(self.subject.find_coordinate(Coordinate(2, 105, rotation=1.07)), node_two)
eq_(self.subject.find_coordinate(Coordinate(3, 104, rotation=1.07)), node_three)
eq_(self.subject.find_coordinate(Coordinate(20, 104, rotation=1.07)), None)

196
test/models/panel_test.py Normal file
View File

@@ -0,0 +1,196 @@
import unittest
from nose.tools import eq_, assert_not_equal
from helix.constants.panel_type import PanelType
from helix.models.coordinate import Coordinate
from helix.models.panel import Panel, PanelData
class PanelTest(unittest.TestCase):
def setUp(self):
self.subject = Panel(
handle="'14DAB3",
blockname="*U13608",
subarray=1,
panel_type=PanelType.Corner,
wind_zone=0,
ballast=5,
link_tray=None,
cross_tray=None,
wind_anchors=0,
seismic_anchors=1,
coordinate=Coordinate(0, 1),
original_coordinate=Coordinate(0, 1),
pressure=3.58,
id=1,
presented_link_tray=2
)
def test_almost_equal_pressure_almost_equal(self):
almost_equal_panel = Panel(
handle="'14DAB3",
blockname="*U13608",
subarray=1,
panel_type=PanelType.Corner,
wind_zone=0,
ballast=5,
link_tray=None,
cross_tray=None,
wind_anchors=0,
seismic_anchors=1,
coordinate=Coordinate(0, 1),
original_coordinate=Coordinate(0, 1),
pressure=3.5805,
id=1,
presented_link_tray=2
)
assert self.subject.almost_equal(almost_equal_panel, decimal=3)
def test_almost_equal_pressure_not_equal(self):
not_equal_panel = Panel(
handle="'14DAB3",
blockname="*U13608",
subarray=1,
panel_type=PanelType.Corner,
wind_zone=0,
ballast=5,
link_tray=None,
cross_tray=None,
wind_anchors=0,
seismic_anchors=1,
coordinate=Coordinate(0, 1),
original_coordinate=Coordinate(0, 1),
pressure=3.585,
id=1,
presented_link_tray=2
)
assert not self.subject.almost_equal(not_equal_panel, decimal=3)
def test_almost_equal_other_attribute_not_equal(self):
not_even_close_panel = Panel(
handle="FOO",
blockname="*U13608",
subarray=1,
panel_type=PanelType.Corner,
wind_zone=0,
ballast=5,
link_tray=None,
cross_tray=None,
wind_anchors=0,
seismic_anchors=1,
coordinate=Coordinate(0, 1),
pressure=3.58,
id=1,
presented_link_tray=2
)
assert not self.subject.almost_equal(not_even_close_panel, decimal=3)
def test_equality_identity(self):
eq_(self.subject, self.subject)
def test_equality_property(self):
same_panel = Panel(
handle="'14DAB3",
blockname="*U13608",
subarray=1,
panel_type=PanelType.Corner,
wind_zone=0,
ballast=5,
link_tray=None,
cross_tray=None,
wind_anchors=0,
seismic_anchors=1,
coordinate=Coordinate(0, 1),
original_coordinate=Coordinate(0, 1),
pressure=3.58,
id=1,
presented_link_tray=2
)
eq_(self.subject, same_panel)
def test_equality_subobject(self):
a = Panel(
handle="'14DAB3",
blockname="*U13608",
id=1,
presented_link_tray=2
)
b = Panel(
handle="'14DAB3",
blockname="*U13608",
id=1,
presented_link_tray=2
)
eq_(a, b)
assert_not_equal(self.subject, a)
def test_is_subset(self):
a = Panel(
handle="'14DAB3",
blockname="*U13608",
id=1,
presented_link_tray=2
)
b = Panel(
handle="'14DAB3",
blockname="*U13608",
id=2,
presented_link_tray=2
)
assert a.is_subset(self.subject)
assert not b.is_subset(self.subject)
def test_repr(self):
expected = '{' \
'"ballast": 5, ' \
'"blockname": "*U13608", ' \
'"coordinate": {"rotation": 0.0, "x": 0, "y": 1}, ' \
'"fuzzy_wind_zone": false, '\
'"handle": "\'14DAB3", ' \
'"id": 1, ' \
'"original_coordinate": {"rotation": 0.0, "x": 0, "y": 1}, ' \
'"panel_type": 0, ' \
'"presented_link_tray": 2, ' \
'"pressure": 3.58, ' \
'"seismic_anchors": 1, ' \
'"subarray": 1, ' \
'"warnings": [], ' \
'"wind_anchors": 0, ' \
'"wind_zone": 0}'
eq_(str(self.subject), expected)
def test_merge_two_panels(self):
a = Panel(
handle="'14DAB3",
blockname="*U13608",
id=1,
presented_link_tray=2
)
b = Panel(
handle="'14DAB3",
blockname="*U13608",
id=2,
presented_link_tray=2,
ballast=10
)
merged = a.merge(b)
eq_(merged, Panel(
handle="'14DAB3",
blockname="*U13608",
id=1,
presented_link_tray=2,
ballast=10
))

View File

@@ -0,0 +1,87 @@
import unittest
from nose.tools import eq_, assert_not_equal
from helix.models.coordinate import Coordinate
from helix.models.subarray import Subarray
class SubarrayTest(unittest.TestCase):
def setUp(self):
self.subject = Subarray(
subarray_number=1,
origin=Coordinate(0, 1),
required_seismic_anchors=1,
start_row=1,
size=144,
weight=16322,
column_count=2,
row_count=4,
column_counted_geometrically=True,
row_counted_geometrically=True
)
def test_equality_identity(self):
eq_(self.subject, self.subject)
def test_equality_property(self):
same_subarray = Subarray(
subarray_number=1,
origin=Coordinate(0, 1),
required_seismic_anchors=1,
start_row=1,
size=144,
weight=16322,
column_count=2,
row_count=4,
column_counted_geometrically=True,
row_counted_geometrically=True
)
eq_(self.subject, same_subarray)
def test_equality_subobject(self):
a = Subarray(
subarray_number=1,
origin=Coordinate(0, 1),
required_seismic_anchors=1,
)
b = Subarray(
subarray_number=1,
origin=Coordinate(0, 1),
required_seismic_anchors=1,
)
eq_(a, b)
assert_not_equal(self.subject, a)
def test_is_subset(self):
a = Subarray(
subarray_number=1,
origin=Coordinate(0, 1),
required_seismic_anchors=1,
)
b = Subarray(
subarray_number=2,
origin=Coordinate(0, 1),
required_seismic_anchors=1,
)
assert a.is_subset(self.subject)
assert not b.is_subset(self.subject)
def test_repr(self):
expected = '{' \
'"column_count": 2, ' \
'"column_counted_geometrically": true, ' \
'"origin": {"rotation": 0.0, "x": 0, "y": 1}, ' \
'"required_seismic_anchors": 1, ' \
'"row_count": 4, ' \
'"row_counted_geometrically": true, ' \
'"size": 144, ' \
'"start_row": 1, ' \
'"subarray_number": 1, ' \
'"weight": 16322' \
'}'
eq_(str(self.subject), expected)

View File

@@ -0,0 +1,34 @@
import unittest
from helix.constants.module_type import ModuleType
from helix.constants.module_type_constants.dual_tilt_128_cell_constants import DualTilt128CellConstants
from helix.constants.module_type_constants.dual_tilt_96_cell_constants import DualTilt96CellConstants
from helix.constants.module_type_constants.single_tilt_128_cell_constants import SingleTilt128CellConstants
from helix.constants.module_type_constants.single_tilt_96_cell_constants import SingleTilt96CellConstants
from helix.constants.system_type import SystemType
class SystemTypeTest(unittest.TestCase):
def test_module_constants_when_single_tilt_and_96Cell_model(self):
system_type = SystemType.singleTilt
module_type = ModuleType.Cell96
assert type(system_type.module_constants(module_type)) is SingleTilt96CellConstants
def test_module_constants_when_dual_tilt_and_96Cell_model(self):
system_type = SystemType.dualTilt
module_type = ModuleType.Cell96
assert type(system_type.module_constants(module_type)) is DualTilt96CellConstants
def test_module_constants_when_single_tilt_and_128Cell_model(self):
system_type = SystemType.singleTilt
module_type = ModuleType.Cell128
assert type(system_type.module_constants(module_type)) is SingleTilt128CellConstants
def test_module_constants_when_dual_tilt_and_128Cell_model(self):
system_type = SystemType.dualTilt
module_type = ModuleType.Cell128
assert type(system_type.module_constants(module_type)) is DualTilt128CellConstants