From 82567984c1ea94cdbebb0049a3bb7c6025e42d3d Mon Sep 17 00:00:00 2001 From: LasNikas Date: Thu, 11 May 2023 11:48:56 +0200 Subject: [PATCH] add tests --- test/unit/setups/merge_shapes.jl | 62 ++++++++++++++++++++++++++++++++ test/unit/setups/setups.jl | 1 + 2 files changed, 63 insertions(+) create mode 100644 test/unit/setups/merge_shapes.jl diff --git a/test/unit/setups/merge_shapes.jl b/test/unit/setups/merge_shapes.jl new file mode 100644 index 000000000..ed2ab59e3 --- /dev/null +++ b/test/unit/setups/merge_shapes.jl @@ -0,0 +1,62 @@ +# 2D +@testset "Merge Shapes 2D" begin + @testset "Rectangular Shapes" begin + shape_1 = RectangularShape(0.1, (3, 4), (-1.0, 1.0), 1.0) + shape_2 = RectangularShape(0.05, (3, 4), (0.0, 1.0), 1.0) + shape_3 = RectangularShape(0.2, (3, 4), (0.0, 0.0), 1.0) + + expected_coords_1 = [-1.0 -1.0 -1.0 -1.0 -0.9 -0.9 -0.9 -0.9 -0.8 -0.8 -0.8 -0.8 0.0 0.0 0.0 0.0 0.05 0.05 0.05 0.05 0.1 0.1 0.1 0.1; + 1.0 1.1 1.2 1.3 1.0 1.1 1.2 1.3 1.0 1.1 1.2 1.3 1.0 1.05 1.1 1.15 1.0 1.05 1.1 1.15 1.0 1.05 1.1 1.15] + expected_coords_2 = [-1.0 -1.0 -1.0 -1.0 -0.9 -0.9 -0.9 -0.9 -0.8 -0.8 -0.8 -0.8 0.0 0.0 0.0 0.0 0.05 0.05 0.05 0.05 0.1 0.1 0.1 0.1 0.0 0.0 0.0 0.0 0.2 0.2 0.2 0.2 0.4 0.4 0.4 0.4; + 1.0 1.1 1.2 1.3 1.0 1.1 1.2 1.3 1.0 1.1 1.2 1.3 1.0 1.05 1.1 1.15 1.0 1.05 1.1 1.15 1.0 1.05 1.1 1.15 0.0 0.2 0.4 0.6 0.0 0.2 0.4 0.6 0.0 0.2 0.4 0.6] + merged_shapes = MergeShapes(shape_1, shape_2) + @test merged_shapes.coordinates ≈ expected_coords_1 + + merged_shapes = MergeShapes(shape_1, shape_2, shape_3) + @test merged_shapes.coordinates ≈ expected_coords_2 + end + + @testset "Circular Shapes" begin + shape_1 = CircularShape(0.1, 0.5, (-1.0, 1.0), 1.0) + shape_2 = CircularShape(0.05, 0.2, (0.0, 1.0), 1.0) + shape_3 = CircularShape(0.15, 1.0, (0.0, -0.2), 1.0) + + expected_coords_1 = [-1.2 -1.1 -1.0 -0.9 -0.8 -1.4 -1.3 -1.2 -1.1 -1.0 -0.9 -0.8 -0.7 -1.4 -1.3 -1.2 -1.1 -1.0 -0.9 -0.8 -0.7 -0.6 -1.4 -1.3 -1.2 -1.1 -1.0 -0.9 -0.8 -0.7 -0.6 -1.4 -1.3 -1.2 -1.1 -1.0 -0.9 -0.8 -0.7 -0.6 -1.4 -1.3 -1.2 -1.1 -1.0 -0.9 -0.8 -0.7 -0.6 -1.4 -1.3 -1.2 -1.1 -1.0 -0.9 -0.8 -0.7 -0.6 -1.4 -1.3 -1.2 -1.1 -1.0 -0.9 -0.8 -0.7 -1.3 -1.2 -1.1 -1.0 -0.9 -0.8 -0.7 0.0 -0.1 -0.05 0.0 0.05 0.1 -0.15 -0.1 -0.05 0.0 0.05 0.1 0.15 -0.15 -0.1 -0.05 0.0 0.05 0.1 0.15 -0.15 -0.1 -0.05 0.0 0.05 0.1 0.15 -0.15 -0.1 -0.05 0.0 0.05 0.1 0.15 -0.15 -0.1 -0.05 0.0 0.05 0.1 0.15 -0.1 -0.05 0.0 0.05 0.1 0.0; + 0.6 0.6 0.6 0.6 0.6 0.7 0.7 0.7 0.7 0.7 0.7 0.7 0.7 0.8 0.8 0.8 0.8 0.8 0.8 0.8 0.8 0.8 0.9 0.9 0.9 0.9 0.9 0.9 0.9 0.9 0.9 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.1 1.1 1.1 1.1 1.1 1.1 1.1 1.1 1.1 1.2 1.2 1.2 1.2 1.2 1.2 1.2 1.2 1.2 1.3 1.3 1.3 1.3 1.3 1.3 1.3 1.3 1.4 1.4 1.4 1.4 1.4 1.4 1.4 0.8 0.85 0.85 0.85 0.85 0.85 0.9 0.9 0.9 0.9 0.9 0.9 0.9 0.95 0.95 0.95 0.95 0.95 0.95 0.95 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.05 1.05 1.05 1.05 1.05 1.05 1.05 1.1 1.1 1.1 1.1 1.1 1.1 1.1 1.15 1.15 1.15 1.15 1.15 1.2] + + expected_coords_2 = [-1.2 -1.1 -1.0 -0.9 -0.8 -1.4 -1.3 -1.2 -1.1 -1.0 -0.9 -0.8 -0.7 -1.4 -1.3 -1.2 -1.1 -1.0 -0.9 -0.8 -0.7 -0.6 -1.4 -1.3 -1.2 -1.1 -1.0 -0.9 -0.8 -0.7 -0.6 -1.4 -1.3 -1.2 -1.1 -1.0 -0.9 -0.8 -0.7 -0.6 -1.4 -1.3 -1.2 -1.1 -1.0 -0.9 -0.8 -0.7 -0.6 -1.4 -1.3 -1.2 -1.1 -1.0 -0.9 -0.8 -0.7 -0.6 -1.4 -1.3 -1.2 -1.1 -1.0 -0.9 -0.8 -0.7 -1.3 -1.2 -1.1 -1.0 -0.9 -0.8 -0.7 0.0 -0.1 -0.05 0.0 0.05 0.1 -0.15000000000000002 -0.1 -0.05 0.0 0.05 0.1 0.15000000000000002 -0.15000000000000002 -0.1 -0.05 0.0 0.05 0.1 0.15000000000000002 -0.15000000000000002 -0.1 -0.05 0.0 0.05 0.1 0.15000000000000002 -0.15000000000000002 -0.1 -0.05 0.0 0.05 0.1 0.15000000000000002 -0.15000000000000002 -0.1 -0.05 0.0 0.05 0.1 0.15000000000000002 -0.1 -0.05 0.0 0.05 0.1 0.0 -0.3 -0.15 0.0 0.15 0.3 -0.6 -0.44999999999999996 -0.3 -0.15 0.0 0.15 0.3 0.44999999999999996 0.6 -0.75 -0.6 -0.44999999999999996 -0.3 -0.15 0.0 0.15 0.3 0.44999999999999996 0.6 0.75 -0.75 -0.6 -0.44999999999999996 -0.3 -0.15 0.0 0.15 0.3 0.44999999999999996 0.6 0.75 -0.8999999999999999 -0.75 -0.6 -0.44999999999999996 -0.3 -0.15 0.0 0.15 0.3 0.44999999999999996 0.6 0.75 0.8999999999999999 -0.8999999999999999 -0.75 -0.6 -0.44999999999999996 -0.3 -0.15 0.0 0.15 0.3 0.44999999999999996 0.6 0.75 0.8999999999999999 -0.8999999999999999 -0.75 -0.6 -0.44999999999999996 -0.3 -0.15 0.0 0.15 0.3 0.44999999999999996 0.6 0.75 0.8999999999999999 -0.8999999999999999 -0.75 -0.6 -0.44999999999999996 -0.3 -0.15 0.0 0.15 0.3 0.44999999999999996 0.6 0.75 0.8999999999999999 -0.8999999999999999 -0.75 -0.6 -0.44999999999999996 -0.3 -0.15 0.0 0.15 0.3 0.44999999999999996 0.6 0.75 0.8999999999999999 -0.75 -0.6 -0.44999999999999996 -0.3 -0.15 0.0 0.15 0.3 0.44999999999999996 0.6 0.75 -0.75 -0.6 -0.44999999999999996 -0.3 -0.15 0.0 0.15 0.3 0.44999999999999996 0.6 0.75 -0.6 -0.44999999999999996 -0.3 -0.15 0.0 0.15 0.3 0.44999999999999996 0.6 -0.3 -0.15 0.0 0.15 0.3; + 0.6 0.6 0.6 0.6 0.6 0.7 0.7 0.7 0.7 0.7 0.7 0.7 0.7 0.8 0.8 0.8 0.8 0.8 0.8 0.8 0.8 0.8 0.9 0.9 0.9 0.9 0.9 0.9 0.9 0.9 0.9 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.1 1.1 1.1 1.1 1.1 1.1 1.1 1.1 1.1 1.2 1.2 1.2 1.2 1.2 1.2 1.2 1.2 1.2 1.3 1.3 1.3 1.3 1.3 1.3 1.3 1.3 1.4 1.4 1.4 1.4 1.4 1.4 1.4 0.8 0.85 0.85 0.85 0.85 0.85 0.9 0.9 0.9 0.9 0.9 0.9 0.9 0.95 0.95 0.95 0.95 0.95 0.95 0.95 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.05 1.05 1.05 1.05 1.05 1.05 1.05 1.1 1.1 1.1 1.1 1.1 1.1 1.1 1.15 1.15 1.15 1.15 1.15 1.2 -1.0999999999999999 -1.0999999999999999 -1.0999999999999999 -1.0999999999999999 -1.0999999999999999 -0.95 -0.95 -0.95 -0.95 -0.95 -0.95 -0.95 -0.95 -0.95 -0.8 -0.8 -0.8 -0.8 -0.8 -0.8 -0.8 -0.8 -0.8 -0.8 -0.8 -0.6499999999999999 -0.6499999999999999 -0.6499999999999999 -0.6499999999999999 -0.6499999999999999 -0.6499999999999999 -0.6499999999999999 -0.6499999999999999 -0.6499999999999999 -0.6499999999999999 -0.6499999999999999 -0.5 -0.5 -0.5 -0.5 -0.5 -0.5 -0.5 -0.5 -0.5 -0.5 -0.5 -0.5 -0.5 -0.35 -0.35 -0.35 -0.35 -0.35 -0.35 -0.35 -0.35 -0.35 -0.35 -0.35 -0.35 -0.35 -0.2 -0.2 -0.2 -0.2 -0.2 -0.2 -0.2 -0.2 -0.2 -0.2 -0.2 -0.2 -0.2 -0.05000000000000002 -0.05000000000000002 -0.05000000000000002 -0.05000000000000002 -0.05000000000000002 -0.05000000000000002 -0.05000000000000002 -0.05000000000000002 -0.05000000000000002 -0.05000000000000002 -0.05000000000000002 -0.05000000000000002 -0.05000000000000002 0.09999999999999998 0.09999999999999998 0.09999999999999998 0.09999999999999998 0.09999999999999998 0.09999999999999998 0.09999999999999998 0.09999999999999998 0.09999999999999998 0.09999999999999998 0.09999999999999998 0.09999999999999998 0.09999999999999998 0.24999999999999994 0.24999999999999994 0.24999999999999994 0.24999999999999994 0.24999999999999994 0.24999999999999994 0.24999999999999994 0.24999999999999994 0.24999999999999994 0.24999999999999994 0.24999999999999994 0.39999999999999997 0.39999999999999997 0.39999999999999997 0.39999999999999997 0.39999999999999997 0.39999999999999997 0.39999999999999997 0.39999999999999997 0.39999999999999997 0.39999999999999997 0.39999999999999997 0.55 0.55 0.55 0.55 0.55 0.55 0.55 0.55 0.55 0.7 0.7 0.7 0.7 0.7] + + merged_shapes = MergeShapes(shape_1, shape_2) + @test merged_shapes.coordinates ≈ expected_coords_1 + + merged_shapes = MergeShapes(shape_1, shape_2, shape_3) + @test merged_shapes.coordinates ≈ expected_coords_2 + end + + @testset "Mixed Shapes" begin + shape_1 = CircularShape(0.1, 0.8, (0.0, 1.0), 1.0) + shape_2 = RectangularShape(0.05, (3, 4), (-0.5, 0.0), 1.0) + + expected_coords = [-0.30000000000000004 -0.2 -0.1 0.0 0.1 0.2 0.30000000000000004 -0.5 -0.4 -0.30000000000000004 -0.2 -0.1 0.0 0.1 0.2 0.30000000000000004 0.4 0.5 -0.6000000000000001 -0.5 -0.4 -0.30000000000000004 -0.2 -0.1 0.0 0.1 0.2 0.30000000000000004 0.4 0.5 0.6000000000000001 -0.6000000000000001 -0.5 -0.4 -0.30000000000000004 -0.2 -0.1 0.0 0.1 0.2 0.30000000000000004 0.4 0.5 0.6000000000000001 -0.7000000000000001 -0.6000000000000001 -0.5 -0.4 -0.30000000000000004 -0.2 -0.1 0.0 0.1 0.2 0.30000000000000004 0.4 0.5 0.6000000000000001 0.7000000000000001 -0.7000000000000001 -0.6000000000000001 -0.5 -0.4 -0.30000000000000004 -0.2 -0.1 0.0 0.1 0.2 0.30000000000000004 0.4 0.5 0.6000000000000001 0.7000000000000001 -0.7000000000000001 -0.6000000000000001 -0.5 -0.4 -0.30000000000000004 -0.2 -0.1 0.0 0.1 0.2 0.30000000000000004 0.4 0.5 0.6000000000000001 0.7000000000000001 -0.7000000000000001 -0.6000000000000001 -0.5 -0.4 -0.30000000000000004 -0.2 -0.1 0.0 0.1 0.2 0.30000000000000004 0.4 0.5 0.6000000000000001 0.7000000000000001 -0.7000000000000001 -0.6000000000000001 -0.5 -0.4 -0.30000000000000004 -0.2 -0.1 0.0 0.1 0.2 0.30000000000000004 0.4 0.5 0.6000000000000001 0.7000000000000001 -0.7000000000000001 -0.6000000000000001 -0.5 -0.4 -0.30000000000000004 -0.2 -0.1 0.0 0.1 0.2 0.30000000000000004 0.4 0.5 0.6000000000000001 0.7000000000000001 -0.7000000000000001 -0.6000000000000001 -0.5 -0.4 -0.30000000000000004 -0.2 -0.1 0.0 0.1 0.2 0.30000000000000004 0.4 0.5 0.6000000000000001 0.7000000000000001 -0.6000000000000001 -0.5 -0.4 -0.30000000000000004 -0.2 -0.1 0.0 0.1 0.2 0.30000000000000004 0.4 0.5 0.6000000000000001 -0.6000000000000001 -0.5 -0.4 -0.30000000000000004 -0.2 -0.1 0.0 0.1 0.2 0.30000000000000004 0.4 0.5 0.6000000000000001 -0.5 -0.4 -0.30000000000000004 -0.2 -0.1 0.0 0.1 0.2 0.30000000000000004 0.4 0.5 -0.30000000000000004 -0.2 -0.1 0.0 0.1 0.2 0.30000000000000004 -0.5 -0.5 -0.5 -0.5 -0.45 -0.45 -0.45 -0.45 -0.4 -0.4 -0.4 -0.4; + 0.29999999999999993 0.29999999999999993 0.29999999999999993 0.29999999999999993 0.29999999999999993 0.29999999999999993 0.29999999999999993 0.3999999999999999 0.3999999999999999 0.3999999999999999 0.3999999999999999 0.3999999999999999 0.3999999999999999 0.3999999999999999 0.3999999999999999 0.3999999999999999 0.3999999999999999 0.3999999999999999 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.6 0.6 0.6 0.6 0.6 0.6 0.6 0.6 0.6 0.6 0.6 0.6 0.6 0.7 0.7 0.7 0.7 0.7 0.7 0.7 0.7 0.7 0.7 0.7 0.7 0.7 0.7 0.7 0.8 0.8 0.8 0.8 0.8 0.8 0.8 0.8 0.8 0.8 0.8 0.8 0.8 0.8 0.8 0.9 0.9 0.9 0.9 0.9 0.9 0.9 0.9 0.9 0.9 0.9 0.9 0.9 0.9 0.9 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 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.1 1.1 1.1 1.2 1.2 1.2 1.2 1.2 1.2 1.2 1.2 1.2 1.2 1.2 1.2 1.2 1.2 1.2 1.3 1.3 1.3 1.3 1.3 1.3 1.3 1.3 1.3 1.3 1.3 1.3 1.3 1.3 1.3 1.4 1.4 1.4 1.4 1.4 1.4 1.4 1.4 1.4 1.4 1.4 1.4 1.4 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.6 1.6 1.6 1.6 1.6 1.6 1.6 1.6 1.6 1.6 1.6 1.7000000000000002 1.7000000000000002 1.7000000000000002 1.7000000000000002 1.7000000000000002 1.7000000000000002 1.7000000000000002 0.0 0.05 0.1 0.15000000000000002 0.0 0.05 0.1 0.15000000000000002 0.0 0.05 0.1 0.15000000000000002] + + merged_shapes = MergeShapes(shape_1, shape_2) + @test merged_shapes.coordinates ≈ expected_coords + end +end + +# 3D +@testset "Merge Shapes 3D" begin + @testset "Rectangular Shapes" begin + shape_1 = RectangularShape(0.1, (3, 4, 2), (-1.0, 1.0, 0.1), 1.0) + shape_2 = RectangularShape(0.05, (3, 4, 5), (-0.5, 0.0, -0.2), 1.0) + + expected_coords = [-1.0 -1.0 -1.0 -1.0 -1.0 -1.0 -1.0 -1.0 -0.9 -0.9 -0.9 -0.9 -0.9 -0.9 -0.9 -0.9 -0.8 -0.8 -0.8 -0.8 -0.8 -0.8 -0.8 -0.8 -0.5 -0.5 -0.5 -0.5 -0.5 -0.5 -0.5 -0.5 -0.5 -0.5 -0.5 -0.5 -0.5 -0.5 -0.5 -0.5 -0.5 -0.5 -0.5 -0.5 -0.45 -0.45 -0.45 -0.45 -0.45 -0.45 -0.45 -0.45 -0.45 -0.45 -0.45 -0.45 -0.45 -0.45 -0.45 -0.45 -0.45 -0.45 -0.45 -0.45 -0.4 -0.4 -0.4 -0.4 -0.4 -0.4 -0.4 -0.4 -0.4 -0.4 -0.4 -0.4 -0.4 -0.4 -0.4 -0.4 -0.4 -0.4 -0.4 -0.4; + 1.0 1.0 1.1 1.1 1.2 1.2 1.3 1.3 1.0 1.0 1.1 1.1 1.2 1.2 1.3 1.3 1.0 1.0 1.1 1.1 1.2 1.2 1.3 1.3 0.0 0.0 0.0 0.0 0.0 0.05 0.05 0.05 0.05 0.05 0.1 0.1 0.1 0.1 0.1 0.15000000000000002 0.15000000000000002 0.15000000000000002 0.15000000000000002 0.15000000000000002 0.0 0.0 0.0 0.0 0.0 0.05 0.05 0.05 0.05 0.05 0.1 0.1 0.1 0.1 0.1 0.15000000000000002 0.15000000000000002 0.15000000000000002 0.15000000000000002 0.15000000000000002 0.0 0.0 0.0 0.0 0.0 0.05 0.05 0.05 0.05 0.05 0.1 0.1 0.1 0.1 0.1 0.15000000000000002 0.15000000000000002 0.15000000000000002 0.15000000000000002 0.15000000000000002; + 0.1 0.2 0.1 0.2 0.1 0.2 0.1 0.2 0.1 0.2 0.1 0.2 0.1 0.2 0.1 0.2 0.1 0.2 0.1 0.2 0.1 0.2 0.1 0.2 -0.2 -0.15000000000000002 -0.1 -0.04999999999999999 0.0 -0.2 -0.15000000000000002 -0.1 -0.04999999999999999 0.0 -0.2 -0.15000000000000002 -0.1 -0.04999999999999999 0.0 -0.2 -0.15000000000000002 -0.1 -0.04999999999999999 0.0 -0.2 -0.15000000000000002 -0.1 -0.04999999999999999 0.0 -0.2 -0.15000000000000002 -0.1 -0.04999999999999999 0.0 -0.2 -0.15000000000000002 -0.1 -0.04999999999999999 0.0 -0.2 -0.15000000000000002 -0.1 -0.04999999999999999 0.0 -0.2 -0.15000000000000002 -0.1 -0.04999999999999999 0.0 -0.2 -0.15000000000000002 -0.1 -0.04999999999999999 0.0 -0.2 -0.15000000000000002 -0.1 -0.04999999999999999 0.0 -0.2 -0.15000000000000002 -0.1 -0.04999999999999999 0.0] + + merged_shapes = MergeShapes(shape_1, shape_2) + @test merged_shapes.coordinates ≈ expected_coords + end +end diff --git a/test/unit/setups/setups.jl b/test/unit/setups/setups.jl index 7d0a94f9c..944c9aebb 100644 --- a/test/unit/setups/setups.jl +++ b/test/unit/setups/setups.jl @@ -1,3 +1,4 @@ include("rectangular_shape.jl") include("circular_shape.jl") include("rectangular_tank.jl") +include("merge_shapes.jl")