-
Notifications
You must be signed in to change notification settings - Fork 519
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sync sum-of-multiples with problem-specifications (#1765)
[no important files changed]
- Loading branch information
Showing
4 changed files
with
107 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
exercises/practice/sum-of-multiples/.meta/test_template.tera
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{% for test in cases %} | ||
#[test] | ||
{% if loop.index != 1 -%} | ||
#[ignore] | ||
{% endif -%} | ||
fn {{ test.description | slugify | replace(from="-", to="_") }}() { | ||
let factors = &{{ test.input.factors | json_encode() }}; | ||
let limit = {{ test.input.limit | json_encode() }}; | ||
let output = {{ crate_name }}::{{ fn_names[0] }}(limit, factors); | ||
let expected = {{ test.expected | json_encode() }}; | ||
assert_eq!(output, expected); | ||
} | ||
{% endfor -%} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 80 additions & 18 deletions
98
exercises/practice/sum-of-multiples/tests/sum-of-multiples.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,96 +1,158 @@ | ||
use sum_of_multiples::*; | ||
|
||
#[test] | ||
fn no_multiples_within_limit() { | ||
assert_eq!(0, sum_of_multiples(1, &[3, 5])) | ||
let factors = &[3, 5]; | ||
let limit = 1; | ||
let output = sum_of_multiples::sum_of_multiples(limit, factors); | ||
let expected = 0; | ||
assert_eq!(output, expected); | ||
} | ||
|
||
#[test] | ||
#[ignore] | ||
fn one_factor_has_multiples_within_limit() { | ||
assert_eq!(3, sum_of_multiples(4, &[3, 5])) | ||
let factors = &[3, 5]; | ||
let limit = 4; | ||
let output = sum_of_multiples::sum_of_multiples(limit, factors); | ||
let expected = 3; | ||
assert_eq!(output, expected); | ||
} | ||
|
||
#[test] | ||
#[ignore] | ||
fn more_than_one_multiple_within_limit() { | ||
assert_eq!(9, sum_of_multiples(7, &[3])) | ||
let factors = &[3]; | ||
let limit = 7; | ||
let output = sum_of_multiples::sum_of_multiples(limit, factors); | ||
let expected = 9; | ||
assert_eq!(output, expected); | ||
} | ||
|
||
#[test] | ||
#[ignore] | ||
fn more_than_one_factor_with_multiples_within_limit() { | ||
assert_eq!(23, sum_of_multiples(10, &[3, 5])) | ||
let factors = &[3, 5]; | ||
let limit = 10; | ||
let output = sum_of_multiples::sum_of_multiples(limit, factors); | ||
let expected = 23; | ||
assert_eq!(output, expected); | ||
} | ||
|
||
#[test] | ||
#[ignore] | ||
fn each_multiple_is_only_counted_once() { | ||
assert_eq!(2318, sum_of_multiples(100, &[3, 5])) | ||
let factors = &[3, 5]; | ||
let limit = 100; | ||
let output = sum_of_multiples::sum_of_multiples(limit, factors); | ||
let expected = 2318; | ||
assert_eq!(output, expected); | ||
} | ||
|
||
#[test] | ||
#[ignore] | ||
fn a_much_larger_limit() { | ||
assert_eq!(233_168, sum_of_multiples(1000, &[3, 5])) | ||
let factors = &[3, 5]; | ||
let limit = 1000; | ||
let output = sum_of_multiples::sum_of_multiples(limit, factors); | ||
let expected = 233168; | ||
assert_eq!(output, expected); | ||
} | ||
|
||
#[test] | ||
#[ignore] | ||
fn three_factors() { | ||
assert_eq!(51, sum_of_multiples(20, &[7, 13, 17])) | ||
let factors = &[7, 13, 17]; | ||
let limit = 20; | ||
let output = sum_of_multiples::sum_of_multiples(limit, factors); | ||
let expected = 51; | ||
assert_eq!(output, expected); | ||
} | ||
|
||
#[test] | ||
#[ignore] | ||
fn factors_not_relatively_prime() { | ||
assert_eq!(30, sum_of_multiples(15, &[4, 6])) | ||
let factors = &[4, 6]; | ||
let limit = 15; | ||
let output = sum_of_multiples::sum_of_multiples(limit, factors); | ||
let expected = 30; | ||
assert_eq!(output, expected); | ||
} | ||
|
||
#[test] | ||
#[ignore] | ||
fn some_pairs_of_factors_relatively_prime_and_some_not() { | ||
assert_eq!(4419, sum_of_multiples(150, &[5, 6, 8])) | ||
let factors = &[5, 6, 8]; | ||
let limit = 150; | ||
let output = sum_of_multiples::sum_of_multiples(limit, factors); | ||
let expected = 4419; | ||
assert_eq!(output, expected); | ||
} | ||
|
||
#[test] | ||
#[ignore] | ||
fn one_factor_is_a_multiple_of_another() { | ||
assert_eq!(275, sum_of_multiples(51, &[5, 25])) | ||
let factors = &[5, 25]; | ||
let limit = 51; | ||
let output = sum_of_multiples::sum_of_multiples(limit, factors); | ||
let expected = 275; | ||
assert_eq!(output, expected); | ||
} | ||
|
||
#[test] | ||
#[ignore] | ||
fn much_larger_factors() { | ||
assert_eq!(2_203_160, sum_of_multiples(10_000, &[43, 47])) | ||
let factors = &[43, 47]; | ||
let limit = 10000; | ||
let output = sum_of_multiples::sum_of_multiples(limit, factors); | ||
let expected = 2203160; | ||
assert_eq!(output, expected); | ||
} | ||
|
||
#[test] | ||
#[ignore] | ||
fn all_numbers_are_multiples_of_1() { | ||
assert_eq!(4950, sum_of_multiples(100, &[1])) | ||
let factors = &[1]; | ||
let limit = 100; | ||
let output = sum_of_multiples::sum_of_multiples(limit, factors); | ||
let expected = 4950; | ||
assert_eq!(output, expected); | ||
} | ||
|
||
#[test] | ||
#[ignore] | ||
fn no_factors_means_an_empty_sum() { | ||
assert_eq!(0, sum_of_multiples(10_000, &[])) | ||
let factors = &[]; | ||
let limit = 10000; | ||
let output = sum_of_multiples::sum_of_multiples(limit, factors); | ||
let expected = 0; | ||
assert_eq!(output, expected); | ||
} | ||
|
||
#[test] | ||
#[ignore] | ||
fn the_only_multiple_of_0_is_0() { | ||
assert_eq!(0, sum_of_multiples(1, &[0])) | ||
let factors = &[0]; | ||
let limit = 1; | ||
let output = sum_of_multiples::sum_of_multiples(limit, factors); | ||
let expected = 0; | ||
assert_eq!(output, expected); | ||
} | ||
|
||
#[test] | ||
#[ignore] | ||
fn the_factor_0_does_not_affect_the_sum_of_multiples_of_other_factors() { | ||
assert_eq!(3, sum_of_multiples(4, &[3, 0])) | ||
let factors = &[3, 0]; | ||
let limit = 4; | ||
let output = sum_of_multiples::sum_of_multiples(limit, factors); | ||
let expected = 3; | ||
assert_eq!(output, expected); | ||
} | ||
|
||
#[test] | ||
#[ignore] | ||
fn solutions_using_include_exclude_must_extend_to_cardinality_greater_than_3() { | ||
assert_eq!(39_614_537, sum_of_multiples(10_000, &[2, 3, 5, 7, 11])) | ||
let factors = &[2, 3, 5, 7, 11]; | ||
let limit = 10000; | ||
let output = sum_of_multiples::sum_of_multiples(limit, factors); | ||
let expected = 39614537; | ||
assert_eq!(output, expected); | ||
} |