From 7f03f375e4f16838f2461f0e8f89b58360481c61 Mon Sep 17 00:00:00 2001 From: Akash G Krishnan Date: Sat, 24 Oct 2020 08:31:34 +0530 Subject: [PATCH 1/3] fix issue #86 fixed issue #86 added test cases @cclauss @Parowicz @StepfenShawn --- maths/fermats_little_theorem.dart | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/maths/fermats_little_theorem.dart b/maths/fermats_little_theorem.dart index 56073fe7..c036ae0a 100644 --- a/maths/fermats_little_theorem.dart +++ b/maths/fermats_little_theorem.dart @@ -1,5 +1,3 @@ -@Skip('currently failing (see issue #86)') - import 'package:test/test.dart'; /* @@ -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); + }, + ); } From c59ea8793f48e0b24ad9f70bdd07796feac55cad Mon Sep 17 00:00:00 2001 From: Akash G Krishnan Date: Sat, 24 Oct 2020 13:04:55 +0530 Subject: [PATCH 2/3] Update fermats_little_theorem.dart Added the suggested changes Added print statements Added support for double --- maths/fermats_little_theorem.dart | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/maths/fermats_little_theorem.dart b/maths/fermats_little_theorem.dart index c036ae0a..8897160d 100644 --- a/maths/fermats_little_theorem.dart +++ b/maths/fermats_little_theorem.dart @@ -1,4 +1,5 @@ import 'package:test/test.dart'; +import 'dart:math'; /* Fermat's little Theorem @@ -19,10 +20,12 @@ void main() { // a prime number int p = 701; - int a = 1000000000; + double a = 1000000000; 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 * pow(b,(p - 2)) % p)); test( 'test 1', () { @@ -34,7 +37,7 @@ void main() { test( 'test 2', () { - expect((a / b) % p == (a * b ^ (p - 2)) % p, isFalse); + expect((a / b) % p == (a * pow(b,(p - 2)) % p), isFalse); }, ); } From 020e2aa2e3f49e709be68fd8ee734a8b901e944e Mon Sep 17 00:00:00 2001 From: Akash G Krishnan Date: Sat, 24 Oct 2020 13:08:13 +0530 Subject: [PATCH 3/3] Update fermats_little_theorem.dart fixed dart format issues --- maths/fermats_little_theorem.dart | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/maths/fermats_little_theorem.dart b/maths/fermats_little_theorem.dart index 8897160d..f6c6a396 100644 --- a/maths/fermats_little_theorem.dart +++ b/maths/fermats_little_theorem.dart @@ -2,9 +2,9 @@ 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,7 +25,7 @@ void main() { // using binary exponentiation function, O(log(p)): print((a / b) % p == (a * binary_exponentiation(b, p - 2, p) % p)); - print((a / b) % p == (a * pow(b,(p - 2)) % p)); + print((a / b) % p == (a * pow(b, (p - 2)) % p)); test( 'test 1', () { @@ -37,7 +37,7 @@ void main() { test( 'test 2', () { - expect((a / b) % p == (a * pow(b,(p - 2)) % p), isFalse); + expect((a / b) % p == (a * pow(b, (p - 2)) % p), isFalse); }, ); }