Skip to content

Commit

Permalink
chore(tricks): add more test cases
Browse files Browse the repository at this point in the history
Signed-off-by: Pouyan Heyratpour <[email protected]>
  • Loading branch information
pouyanh committed Dec 4, 2024
1 parent 9e7a4b7 commit 8e116da
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion tricks/mathx/arithmetic.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func MinorCoprimes(n int) []int {
return CoprimesInRange(n, 1, n-1)
}

// EulerTotient counts the positive integers up to the given number (n) that are relatively prime to (n)
// EulerTotient aka φ(n) counts the positive integers up to the given number (n) that are relatively prime to (n)
func EulerTotient(n int) int {
pff := PrimeFactors(n)

Expand Down
16 changes: 15 additions & 1 deletion tricks/mathx/arithmetic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,11 @@ func TestPrimitiveRootsWithRrs(t *testing.T) {
2: {2, 1},
}, mathx.PrimitiveRootsWithRrs(3))

assert.Equal(t, map[int][]int{
2: {2, 4, 3, 1},
3: {3, 4, 2, 1},
}, mathx.PrimitiveRootsWithRrs(5))

assert.Equal(t, map[int][]int{
3: {3, 2, 6, 4, 5, 1},
5: {5, 4, 6, 2, 3, 1},
Expand All @@ -274,6 +279,13 @@ func TestPrimitiveRootsWithRrs(t *testing.T) {
7: {7, 9, 3, 1},
}, mathx.PrimitiveRootsWithRrs(10))

assert.Equal(t, map[int][]int{
2: {2, 4, 8, 5, 10, 9, 7, 3, 6, 1},
6: {6, 3, 7, 9, 10, 5, 8, 4, 2, 1},
7: {7, 5, 2, 3, 10, 4, 6, 9, 8, 1},
8: {8, 9, 6, 4, 10, 3, 2, 5, 7, 1},
}, mathx.PrimitiveRootsWithRrs(11))

assert.Equal(t, map[int][]int{
3: {3, 9, 10, 13, 5, 15, 11, 16, 14, 8, 7, 4, 12, 2, 6, 1},
5: {5, 8, 6, 13, 14, 2, 10, 16, 12, 9, 11, 4, 3, 15, 7, 1},
Expand All @@ -285,7 +297,9 @@ func TestPrimitiveRootsWithRrs(t *testing.T) {
14: {14, 9, 7, 13, 12, 15, 6, 16, 3, 8, 10, 4, 5, 2, 11, 1},
}, mathx.PrimitiveRootsWithRrs(17))

nn := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 20, 21, 22, 23, 24, 25, 49, 50, 100}
nn := []int{
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 20, 21, 22, 23, 24, 25, 49, 50, 95, 96, 97, 98, 99, 100,
}
for _, n := range nn {
prr, phi := mathx.PrimitiveRootsWithRrs(n), mathx.EulerTotient(n)
for _, pra := range prr {
Expand Down

0 comments on commit 8e116da

Please sign in to comment.