@@ -182,6 +182,42 @@ def test_phys(self):
182182 self .assertAlmostEqual (var .decode_phys (128 ), 12.8 )
183183 self .assertEqual (var .encode_phys (- 0.1 ), - 1 )
184184
185+ def test_phys_factor_1_int64_roundtrip (self ):
186+ """int64 values must survive encode_phys when factor is 1."""
187+ var = od .ODVariable ("Test UNSIGNED64" , 0x1000 )
188+ var .data_type = od .UNSIGNED64
189+ value = 0x55554444AAAABBBB
190+ self .assertEqual (var .encode_phys (value ), value )
191+
192+ def test_phys_factor_1_preserves_int (self ):
193+ """encode_phys with factor=1 must not convert int to float."""
194+ var = od .ODVariable ("Test INTEGER32" , 0x1000 )
195+ var .data_type = od .INTEGER32
196+ self .assertIsInstance (var .encode_phys (42 ), int )
197+
198+ def test_phys_factor_1000_rounds (self ):
199+ """Integer factor > 1 uses float rounding behaviour, not truncating division."""
200+ var = od .ODVariable ("Test INTEGER32" , 0x1000 )
201+ var .data_type = od .INTEGER32
202+ var .factor = 1000
203+ # 5555 / 1000 = 5.555 → round → 6
204+ self .assertEqual (var .encode_phys (5555 ), 6 )
205+
206+ def test_phys_float_factor (self ):
207+ """Float factor uses float division + round."""
208+ var = od .ODVariable ("Test INTEGER16" , 0x1000 )
209+ var .data_type = od .INTEGER16
210+ var .factor = 0.5
211+ # 10 / 0.5 = 20
212+ self .assertEqual (var .encode_phys (10 ), 20 )
213+
214+ def test_phys_float_factor_decodes_to_float (self ):
215+ """decode_phys with float factor ensures a float result."""
216+ var = od .ODVariable ("Test INTEGER32" , 0x1000 )
217+ var .data_type = od .INTEGER32
218+ var .factor = 1.0
219+ self .assertIsInstance (var .decode_phys (42 ), float )
220+
185221 def test_desc (self ):
186222 var = od .ODVariable ("Test UNSIGNED8" , 0x1000 )
187223 var .data_type = od .UNSIGNED8
0 commit comments