| 1902 | } |
| 1903 | |
| 1904 | func TestInEpsilon(t *testing.T) { |
| 1905 | mockT := new(testing.T) |
| 1906 | |
| 1907 | cases := []struct { |
| 1908 | a, b interface{} |
| 1909 | epsilon float64 |
| 1910 | }{ |
| 1911 | {uint8(2), uint16(2), .001}, |
| 1912 | {2.1, 2.2, 0.1}, |
| 1913 | {2.2, 2.1, 0.1}, |
| 1914 | {-2.1, -2.2, 0.1}, |
| 1915 | {-2.2, -2.1, 0.1}, |
| 1916 | {uint64(100), uint8(101), 0.01}, |
| 1917 | {0.1, -0.1, 2}, |
| 1918 | {0.1, 0, 2}, |
| 1919 | {math.NaN(), math.NaN(), 1}, |
| 1920 | {time.Second, time.Second + time.Millisecond, 0.002}, |
| 1921 | } |
| 1922 | |
| 1923 | for _, tc := range cases { |
| 1924 | True(t, InEpsilon(t, tc.a, tc.b, tc.epsilon, "Expected %V and %V to have a relative difference of %v", tc.a, tc.b, tc.epsilon), "test: %q", tc) |
| 1925 | } |
| 1926 | |
| 1927 | cases = []struct { |
| 1928 | a, b interface{} |
| 1929 | epsilon float64 |
| 1930 | }{ |
| 1931 | {uint8(2), int16(-2), .001}, |
| 1932 | {uint64(100), uint8(102), 0.01}, |
| 1933 | {2.1, 2.2, 0.001}, |
| 1934 | {2.2, 2.1, 0.001}, |
| 1935 | {2.1, -2.2, 1}, |
| 1936 | {2.1, "bla-bla", 0}, |
| 1937 | {0.1, -0.1, 1.99}, |
| 1938 | {0, 0.1, 2}, // expected must be different to zero |
| 1939 | {time.Second, time.Second + 10*time.Millisecond, 0.002}, |
| 1940 | {math.NaN(), 0, 1}, |
| 1941 | {0, math.NaN(), 1}, |
| 1942 | {0, 0, math.NaN()}, |
| 1943 | } |
| 1944 | |
| 1945 | for _, tc := range cases { |
| 1946 | False(t, InEpsilon(mockT, tc.a, tc.b, tc.epsilon, "Expected %V and %V to have a relative difference of %v", tc.a, tc.b, tc.epsilon)) |
| 1947 | } |
| 1948 | |
| 1949 | } |
| 1950 | |
| 1951 | func TestInEpsilonSlice(t *testing.T) { |
| 1952 | mockT := new(testing.T) |