Skip to content

Commit

Permalink
fix issue TheAlgorithms#86
Browse files Browse the repository at this point in the history
fixed issue TheAlgorithms#86 
added test cases
@cclauss @Parowicz @StepfenShawn
  • Loading branch information
akashgkrishnan authored Oct 24, 2020
1 parent 9aba62e commit 7f03f37
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions maths/fermats_little_theorem.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
@Skip('currently failing (see issue #86)')

import 'package:test/test.dart';

/*
Expand All @@ -21,12 +19,22 @@ void main() {
// a prime number
int p = 701;

double a = 1000000000;
int a = 1000000000;
int b = 10;

// using binary exponentiation function, O(log(p)):
print((a / b) % p == (a * binary_exponentiation(b, p - 2, p)) % p);

test(
'test 1',
() {
expect(
(a / b) % p == (a * binary_exponentiation(b, p - 2, p) % p), isTrue);
},
);
// using Python operators:
print((a / b) % p == (a * b ^ (p - 2)) % p);
test(
'test 2',
() {
expect((a / b) % p == (a * b ^ (p - 2)) % p, isFalse);
},
);
}

0 comments on commit 7f03f37

Please sign in to comment.