diff options
| author | Adrien Hopkins <adrien.p.hopkins@gmail.com> | 2023-08-21 09:35:27 -0500 |
|---|---|---|
| committer | Adrien Hopkins <adrien.p.hopkins@gmail.com> | 2023-08-21 09:56:06 -0500 |
| commit | 547c63fbf0c6dd673e8caf83ea7f9eeb679b5f5c (patch) | |
| tree | 31c07bcab4ffb2c18d287f50d471660cd65bac39 /factors/factors_test.go | |
| parent | 30e92c33303535a86e56824b668f46ad0c6261a8 (diff) | |
Add MTC to output
(MTC = Multiplication Table Complexity)
Diffstat (limited to 'factors/factors_test.go')
| -rw-r--r-- | factors/factors_test.go | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/factors/factors_test.go b/factors/factors_test.go index 77c5f4a..db6e098 100644 --- a/factors/factors_test.go +++ b/factors/factors_test.go @@ -100,6 +100,36 @@ func TestBasicRank(t *testing.T) { tableTest(t, BasicRank, basicRankCases, stdEquals[string], "BasicRank") } +var gcdCases = map[struct{ a, b uint }]uint{ + {0, 0}: 0, {1, 1}: 1, + {6, 10}: 2, {10, 6}: 2, + {12, 20}: 4, {20, 12}: 4, + {20, 55}: 5, {55, 20}: 5, + {60, 120}: 60, {120, 60}: 60, +} + +// a version of gcd() for testing purposes +func gcdTest(c struct{ a, b uint }) uint { + return gcd(c.a, c.b) +} + +func TestGCD(t *testing.T) { + tableTest(t, gcdTest, gcdCases, stdEquals[uint], "gcd") +} + +var mtcCases = map[uint]uint{ + 2: 0, 3: 0, 4: 2, 5: 10, 6: 8, + 7: 28, 8: 26, 9: 42, 10: 42, 11: 88, 12: 52, + 13: 130, 14: 100, 15: 116, 16: 138, 18: 146, + 20: 190, 24: 252, 28: 416, 30: 380, 32: 618, 36: 598, + 48: 1100, 60: 1496, 64: 2602, 90: 3662, 120: 6080, + 210: 18542, 360: 54362, 840: 270122, 2520: 2363528, 5040: 9409112, +} + +func TestMTC(t *testing.T) { + tableTest(t, MTC, mtcCases, stdEquals[uint], "MTC") +} + // to be used as the equal paramater for tableTest func stdEquals[T comparable](a, b T) bool { return a == b } |
