Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(554)

Unified Diff: tests/corelib/int_modulo_arith_test.dart

Issue 1211473002: Make int.gcd accept zero operands. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Address comment. Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tests/corelib/big_integer_arith_vm_test.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/corelib/int_modulo_arith_test.dart
diff --git a/tests/corelib/int_modulo_arith_test.dart b/tests/corelib/int_modulo_arith_test.dart
index 87d253d36eb28f2296a18c8fc31df180e07a0804..9d5b9eb96ec9cca1019e3393c25d0933318c7eca 100644
--- a/tests/corelib/int_modulo_arith_test.dart
+++ b/tests/corelib/int_modulo_arith_test.dart
@@ -141,14 +141,15 @@ testGcd() {
// Test that gcd of value and other (non-negative) is expectedResult.
// Tests all combinations of positive and negative values and order of
// operands, so use positive values and order is not important.
- test(value, other, [expectedResult]) {
- assert(value % expectedResult == 0); // Check for bug in test.
- assert(other % expectedResult == 0);
+ test(value, other, expectedResult) {
+ // Check for bug in test.
+ assert(expectedResult == 0 || value % expectedResult == 0);
+ assert(expectedResult == 0 || other % expectedResult == 0);
callCombos(value, other, (a, b) {
var result = a.gcd(b);
/// Check that the result is a divisor.
- Expect.equals(0, a % result, "$result | $a");
- Expect.equals(0, b % result, "$result | $b");
+ Expect.equals(0, result == 0 ? a : a % result, "$result | $a");
+ Expect.equals(0, result == 0 ? b : b % result, "$result | $b");
// Check for bug in test. If assert fails, the expected value is too low,
// and the gcd call has found a greater common divisor.
assert(result >= expectedResult);
@@ -163,9 +164,8 @@ testGcd() {
});
}
- // Throws if either operand is zero, and if both operands are zero.
- testThrows(0, 1000);
- testThrows(0, 0);
+ testThrows(2.5, 5); // Not a method on double.
+ testThrows(5, 2.5); // Not accepting non-int arguments.
// Format:
// test(value1, value2, expectedResult);
@@ -176,6 +176,9 @@ testGcd() {
test(9999, 7272, 909); // Larger numbers
+ test(0, 1000, 1000); // One operand is zero.
+ test(0, 0, 0); // Both operands are zero.
+
// Multiplying both operands by a number multiplies result by same number.
test(693, 609, 21);
test(693 << 5, 609 << 5, 21 << 5);
« no previous file with comments | « tests/corelib/big_integer_arith_vm_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698