1+ @testitem " Product Construction" begin
2+ using SpaceDataModel: Product, func, NoMetadata
3+
4+ # Test basic construction with minimal parameters
5+ p1 = Product ([1 , 2 , 3 ])
6+ @test parent (p1) == [1 , 2 , 3 ]
7+ @test func (p1) === identity
8+ @test p1. name == " "
9+ @test p1. metadata isa NoMetadata # NoMetadata() becomes Dict when merged with kwargs
10+
11+ # Test construction with transformation function
12+ p2 = Product ([1 , 2 , 3 ], x -> x .* 2 )
13+ @test parent (p2) == [1 , 2 , 3 ]
14+ @test func (p2)([1 , 2 , 3 ]) == [2 , 4 , 6 ]
15+
16+ # Test construction with name
17+ p3 = Product ([1 , 2 , 3 ]; name= " test_data" )
18+ @test p3. name == " test_data"
19+
20+ # Test construction with metadata
21+ p4 = Product ([1 , 2 , 3 ]; metadata= Dict (" units" => " m/s" ))
22+ @test p4. metadata[" units" ] == " m/s"
23+
24+ # Test construction with kwargs that become metadata
25+ p5 = Product ([1 , 2 , 3 ]; units= " m/s" , description= " velocity" )
26+ @test p5. metadata isa Base. Pairs
27+ @test p5. metadata[:units ] == " m/s"
28+ @test p5. metadata[:description ] == " velocity"
29+
30+ # Test full constructor
31+ p6 = Product ([1 , 2 , 3 ], x -> x .+ 1 , " full_test" , Dict (" key" => " value" ))
32+ @test parent (p6) == [1 , 2 , 3 ]
33+ @test func (p6)([1 , 2 , 3 ]) == [2 , 3 , 4 ]
34+ @test p6. name == " full_test"
35+ @test p6. metadata[" key" ] == " value"
36+ end
37+
38+ @testitem " Product Methods" begin
39+ using SpaceDataModel: Product
40+ p1 = Product ([1 , 4 , 9 ], x -> sqrt .(x))
41+ @test all (p1 .== [1 , 4 , 9 ])
42+ @test_nowarn sprint (show, p1)
43+ end
44+
45+ @testitem " Product Function Application and Composition" begin
46+ using SpaceDataModel: Product
47+
48+ p1 = Product ([1 , 2 , 3 ], x -> x .* 2 )
49+ @test p1 () == [2 , 4 , 6 ]
50+
51+ # Test calling with additional arguments
52+ p2 = Product ([1 , 2 , 3 ], (x, y) -> x .+ y)
53+ @test p2 (10 ) == [11 , 12 , 13 ]
54+
55+ # Test with identity transformation
56+ p3 = Product ([1 , 2 , 3 ])
57+ @test p3 () == [1 , 2 , 3 ]
58+
59+ # Test composition with function on left
60+ p1 = Product ([1 , 2 , 3 ], x -> x .* 2 )
61+ p2 = Product ([1 , 2 , 3 ], x -> x .+ 1 )
62+ p3 = (x -> x .+ 1 ) ∘ p1
63+ @test p3 () == [3 , 5 , 7 ] # (x * 2) + 1
64+
65+ # Test composition with function on right
66+ p4 = p1 ∘ (x -> x .+ 1 )
67+ @test p4 () == [4 , 6 , 8 ] # (x + 1) * 2
68+
69+ # Test composition between products
70+ p5 = p1 ∘ p2
71+ @test p5 () == [4 , 6 , 8 ] # (x + 1) * 2
72+ end
73+
74+ @testitem " Product Setting Operations" begin
75+ using SpaceDataModel: Product, set
76+
77+ # Test immutable set operations
78+ p1 = Product ([1 , 2 , 3 ]; name= " original" )
79+
80+ # Test setting name
81+ p2 = set (p1; name= " new_name" )
82+ @test p2. name == " new_name"
83+ @test p1. name == " original" # Original unchanged
84+
85+ # Test setting data
86+ data = [4 , 5 , 6 ]
87+ @test set (p1; data)() == data
88+ @test set (p1, data)() == data
89+
90+ # Test setting metadata
91+ p4 = set (p1; units= " m/s" , description= " velocity" )
92+ @test p4. metadata[:units ] == " m/s"
93+ @test p4. metadata[:description ] == " velocity"
94+ end
0 commit comments