diff --git a/maths/fermats_little_theorem.dart b/maths/fermats_little_theorem.dart index 56073fe7..f6c6a396 100644 --- a/maths/fermats_little_theorem.dart +++ b/maths/fermats_little_theorem.dart @@ -1,11 +1,10 @@ -@Skip('currently failing (see issue #86)') - import 'package:test/test.dart'; +import 'dart:math'; /* - Fermat's little Theorem - Translated from TheAlgorithms/Python -*/ + Fermat's little Theorem + Translated from TheAlgorithms/Python + */ binary_exponentiation(a, n, mod) { if (n == 0) { return 1; @@ -25,8 +24,20 @@ void main() { int b = 10; // using binary exponentiation function, O(log(p)): - print((a / b) % p == (a * binary_exponentiation(b, p - 2, p)) % p); - + print((a / b) % p == (a * binary_exponentiation(b, p - 2, p) % p)); + print((a / b) % p == (a * pow(b, (p - 2)) % 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 * pow(b, (p - 2)) % p), isFalse); + }, + ); }