Skip to content

assert.InEpsilon float #1839

@szuecs

Description

@szuecs

Description

As far as I read the code calcRelativeError() is wrong for "expected" values lower than 1
The division is an error for values in interval 0..1

math.Abs(af-bf) / math.Abs(af)

// example:
abs(0.1-0.14) / abs(0.1)
0.04 / 0.1
0.4

Step To Reproduce

func TestFoo(t *testing.T) {
	expected := 0.1
	epsilon := 0.2
	successRate := 0.14

	if !assert.InEpsilon(t, expected, successRate, epsilon, fmt.Sprintf("Test should have a success rate between %0.2f < %0.2f < %0.2f", expected-epsilon, successRate, expected+epsilon)) {
		t.Fatal("FAIL")
	}
}

Expected behavior

success

Actual behavior

--- FAIL: TestFoo (0.00s)
                Error:          Relative error is too high: 0.2 (expected)
                                        < 0.4000000000000001 (actual)
                Test:           TestFoo
                Messages:       Test should have a success rate between -0.10 < 0.14 < 0.30
    redis_test.go:614: FAIL
FAIL

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions