Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions compare_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,19 @@ var (
)

func ignoreUnpredictable(k string, v interface{}) bool {
if _, ok := v.(float64); ok {
return true
}
// Date and EpochTime are regenerated on every build by design.
if k == "Date" || k == "EpochTime" {
return true
}

return false
}

// approxFloats compares float64 values with a small absolute tolerance
// consistent with number smoothing (positions 3dp, scale 2dp, colors 5dp),
// rather than ignoring them outright.
var approxFloats = cmpopts.EquateApprox(0, 1e-4)

func compareDelta(t *testing.T, filea, fileb string) error {
a, err := file.ReadRawFile(filea)
if err != nil {
Expand Down Expand Up @@ -60,7 +63,7 @@ func compareDelta(t *testing.T, filea, fileb string) error {
delete(a, osKey)
delete(b, osKey)

if diff := cmp.Diff(a, b, cmpopts.IgnoreMapEntries(ignoreUnpredictable)); diff != "" {
if diff := cmp.Diff(a, b, cmpopts.IgnoreMapEntries(ignoreUnpredictable), approxFloats); diff != "" {
t.Errorf("want != got:\n%v\n", diff)
}
return nil
Expand Down Expand Up @@ -154,7 +157,7 @@ func compareObjs(t *testing.T, guid string, a, b map[string]interface{}) error {
return fmt.Errorf("in obj %s, one has sub-objects, the other does not", guid)
}

if diff := cmp.Diff(a, b, cmpopts.IgnoreMapEntries(ignoreUnpredictable)); diff != "" {
if diff := cmp.Diff(a, b, cmpopts.IgnoreMapEntries(ignoreUnpredictable), approxFloats); diff != "" {
t.Errorf("want != got:\n%v\n", diff)
}
return nil
Expand Down
10 changes: 6 additions & 4 deletions tests/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,7 @@ func TestAllReverseThenBuild(t *testing.T) {
t.Fatalf("output.json not parsed : %v", err)
}
ignoreUnpredictable := func(k string, v interface{}) bool {
if _, ok := v.(float64); ok {
return true
}
// Date and EpochTime are regenerated on every build by design.
if k == "Date" || k == "EpochTime" {
return true
}
Expand Down Expand Up @@ -133,7 +131,11 @@ func TestAllReverseThenBuild(t *testing.T) {
normalizeBundledLua(want)
normalizeBundledLua(got)

if diff := cmp.Diff(want, got, cmpopts.IgnoreMapEntries(ignoreUnpredictable)); diff != "" {
// Floats are compared approximately rather than skipped. Smoothing rounds
// positions to 3dp, scale to 2dp, and colors to 5dp, so an absolute
// tolerance of 1e-4 comfortably absorbs rounding noise while still
// catching any real numeric corruption in the round trip.
if diff := cmp.Diff(want, got, cmpopts.IgnoreMapEntries(ignoreUnpredictable), cmpopts.EquateApprox(0, 1e-4)); diff != "" {
t.Errorf("want != got:\n%v\n", diff)
}
})
Expand Down
32 changes: 16 additions & 16 deletions tests/testdata/e2e/GHE_Dev_no_objects.json
Original file line number Diff line number Diff line change
Expand Up @@ -1293,50 +1293,50 @@
"SnapPoints": [
{
"Position": {
"x": -36.0014,
"y": 1.6801,
"x": -36.001,
"y": 1.68,
"z": -40
},
"Rotation": {
"x": -0.0001,
"y": 180.0016,
"x": 0,
"y": 180,
"z": 0
}
},
{
"Position": {
"x": -12.001,
"y": 1.6801,
"y": 1.68,
"z": -40
},
"Rotation": {
"x": -0.0003,
"y": 180.0298,
"z": -0.0001
"x": 0,
"y": 180,
"z": 0
}
},
{
"Position": {
"x": 12.001,
"y": 1.6801,
"y": 1.68,
"z": -40
},
"Rotation": {
"x": -0.0003,
"y": 180.0294,
"x": 0,
"y": 180,
"z": 0
}
},
{
"Position": {
"x": 36.0009,
"y": 1.6801,
"x": 36.001,
"y": 1.68,
"z": -40
},
"Rotation": {
"x": -0.0003,
"y": 180.0302,
"z": -0.0001
"x": 0,
"y": 180,
"z": 0
}
}
],
Expand Down
32 changes: 16 additions & 16 deletions tests/testdata/e2e/GHE_Dev_no_objects_no_lua.json
Original file line number Diff line number Diff line change
Expand Up @@ -1293,50 +1293,50 @@
"SnapPoints": [
{
"Position": {
"x": -36.0014,
"y": 1.6801,
"x": -36.001,
"y": 1.68,
"z": -40
},
"Rotation": {
"x": -0.0001,
"y": 180.0016,
"x": 0,
"y": 180,
"z": 0
}
},
{
"Position": {
"x": -12.001,
"y": 1.6801,
"y": 1.68,
"z": -40
},
"Rotation": {
"x": -0.0003,
"y": 180.0298,
"z": -0.0001
"x": 0,
"y": 180,
"z": 0
}
},
{
"Position": {
"x": 12.001,
"y": 1.6801,
"y": 1.68,
"z": -40
},
"Rotation": {
"x": -0.0003,
"y": 180.0294,
"x": 0,
"y": 180,
"z": 0
}
},
{
"Position": {
"x": 36.0009,
"y": 1.6801,
"x": 36.001,
"y": 1.68,
"z": -40
},
"Rotation": {
"x": -0.0003,
"y": 180.0302,
"z": -0.0001
"x": 0,
"y": 180,
"z": 0
}
}
],
Expand Down
Loading