@@ -839,77 +839,80 @@ mod tests {
839
839
#[ test]
840
840
fn test_outputs_match_no_epsilon ( ) {
841
841
let runner = Runner :: new ( PathBuf :: from ( "dummy_base" ) ) ;
842
-
842
+
843
843
// Exact match should work
844
844
assert ! ( runner. outputs_match( b"hello" , b"hello" , None , OutputType :: Raw ) ) ;
845
-
845
+
846
846
// Different content should not match
847
847
assert ! ( !runner. outputs_match( b"hello" , b"world" , None , OutputType :: Raw ) ) ;
848
848
}
849
849
850
850
#[ test]
851
851
fn test_outputs_match_with_epsilon_f32 ( ) {
852
852
let runner = Runner :: new ( PathBuf :: from ( "dummy_base" ) ) ;
853
-
853
+
854
854
// Prepare test data - two floats with small difference
855
855
let val1: f32 = 1.0 ;
856
856
let val2: f32 = 1.00001 ;
857
857
let arr1 = [ val1] ;
858
858
let arr2 = [ val2] ;
859
859
let bytes1 = bytemuck:: cast_slice ( & arr1) ;
860
860
let bytes2 = bytemuck:: cast_slice ( & arr2) ;
861
-
861
+
862
862
// Should not match without epsilon
863
863
assert ! ( !runner. outputs_match( bytes1, bytes2, None , OutputType :: F32 ) ) ;
864
-
864
+
865
865
// Should match with sufficient epsilon
866
866
assert ! ( runner. outputs_match( bytes1, bytes2, Some ( 0.0001 ) , OutputType :: F32 ) ) ;
867
-
867
+
868
868
// Should not match with too small epsilon
869
869
assert ! ( !runner. outputs_match( bytes1, bytes2, Some ( 0.000001 ) , OutputType :: F32 ) ) ;
870
870
}
871
871
872
872
#[ test]
873
873
fn test_outputs_match_with_epsilon_f64 ( ) {
874
874
let runner = Runner :: new ( PathBuf :: from ( "dummy_base" ) ) ;
875
-
875
+
876
876
// Prepare test data - two doubles with small difference
877
877
let val1: f64 = 1.0 ;
878
878
let val2: f64 = 1.00001 ;
879
879
let arr1 = [ val1] ;
880
880
let arr2 = [ val2] ;
881
881
let bytes1 = bytemuck:: cast_slice ( & arr1) ;
882
882
let bytes2 = bytemuck:: cast_slice ( & arr2) ;
883
-
883
+
884
884
// Should not match without epsilon
885
885
assert ! ( !runner. outputs_match( bytes1, bytes2, None , OutputType :: F64 ) ) ;
886
-
886
+
887
887
// Should match with sufficient epsilon
888
888
assert ! ( runner. outputs_match( bytes1, bytes2, Some ( 0.0001 ) , OutputType :: F64 ) ) ;
889
-
889
+
890
890
// Should not match with too small epsilon
891
891
assert ! ( !runner. outputs_match( bytes1, bytes2, Some ( 0.000001 ) , OutputType :: F64 ) ) ;
892
892
}
893
893
894
894
#[ test]
895
895
fn test_group_outputs_with_epsilon ( ) {
896
896
let runner = Runner :: new ( PathBuf :: from ( "dummy_base" ) ) ;
897
-
897
+
898
898
// Create float outputs with small differences
899
899
let val1: f32 = 1.0 ;
900
900
let val2: f32 = 1.00001 ;
901
901
let val3: f32 = 2.0 ;
902
-
903
- let pkg1 = dummy_package_output ( "foo" , "/path/to/foo" , bytemuck:: cast_slice ( & [ val1] ) , "tmp1" ) ;
904
- let pkg2 = dummy_package_output ( "bar" , "/path/to/bar" , bytemuck:: cast_slice ( & [ val2] ) , "tmp2" ) ;
905
- let pkg3 = dummy_package_output ( "baz" , "/path/to/baz" , bytemuck:: cast_slice ( & [ val3] ) , "tmp3" ) ;
906
-
902
+
903
+ let pkg1 =
904
+ dummy_package_output ( "foo" , "/path/to/foo" , bytemuck:: cast_slice ( & [ val1] ) , "tmp1" ) ;
905
+ let pkg2 =
906
+ dummy_package_output ( "bar" , "/path/to/bar" , bytemuck:: cast_slice ( & [ val2] ) , "tmp2" ) ;
907
+ let pkg3 =
908
+ dummy_package_output ( "baz" , "/path/to/baz" , bytemuck:: cast_slice ( & [ val3] ) , "tmp3" ) ;
909
+
907
910
let outputs = vec ! [ pkg1, pkg2, pkg3] ;
908
-
911
+
909
912
// Without epsilon, val1 and val2 should be in different groups
910
913
let groups = runner. group_outputs ( & outputs, None , OutputType :: F32 ) ;
911
914
assert_eq ! ( groups. len( ) , 3 ) ;
912
-
915
+
913
916
// With epsilon, val1 and val2 should be in the same group
914
917
let groups_with_epsilon = runner. group_outputs ( & outputs, Some ( 0.0001 ) , OutputType :: F32 ) ;
915
918
assert_eq ! ( groups_with_epsilon. len( ) , 2 ) ;
@@ -919,7 +922,8 @@ mod tests {
919
922
fn test_invalid_metadata_json ( ) {
920
923
// Test that invalid JSON in metadata file causes proper error
921
924
let metadata_content = "{ invalid json }" ;
922
- let result: Result < difftest:: config:: TestMetadata , _ > = serde_json:: from_str ( metadata_content) ;
925
+ let result: Result < difftest:: config:: TestMetadata , _ > =
926
+ serde_json:: from_str ( metadata_content) ;
923
927
assert ! ( result. is_err( ) ) ;
924
928
// Just check that it's an error, don't check the specific message
925
929
}
@@ -929,18 +933,20 @@ mod tests {
929
933
// This test verifies that when packages have different output types,
930
934
// the runner returns an error. This tests the code at line 340-347
931
935
// where we check: if output_type != Some(metadata.output_type)
932
-
936
+
933
937
// We can't easily test the full run_test_case flow without real binaries,
934
938
// but we can at least verify the error is constructed properly
935
-
939
+
936
940
// Test that the error message is properly formatted
937
941
let error = RunnerError :: Config {
938
942
msg : format ! (
939
943
"Package '{}' has output type {:?}, but previous packages have {:?}" ,
940
- "test_pkg" , OutputType :: F32 , Some ( OutputType :: F64 )
944
+ "test_pkg" ,
945
+ OutputType :: F32 ,
946
+ Some ( OutputType :: F64 )
941
947
) ,
942
948
} ;
943
-
949
+
944
950
match error {
945
951
RunnerError :: Config { msg } => {
946
952
assert ! ( msg. contains( "test_pkg" ) ) ;
@@ -954,14 +960,14 @@ mod tests {
954
960
#[ test]
955
961
fn test_metadata_parsing_error_message ( ) {
956
962
// Test that metadata parsing errors are formatted correctly
957
-
963
+
958
964
let error = RunnerError :: Config {
959
965
msg : format ! (
960
966
"Failed to parse metadata for package '{}': {}" ,
961
967
"test_pkg" , "invalid JSON"
962
968
) ,
963
969
} ;
964
-
970
+
965
971
match error {
966
972
RunnerError :: Config { msg } => {
967
973
assert ! ( msg. contains( "Failed to parse metadata" ) ) ;
@@ -971,5 +977,4 @@ mod tests {
971
977
_ => panic ! ( "Wrong error type" ) ,
972
978
}
973
979
}
974
-
975
980
}
0 commit comments