Skip to content

Commit

Permalink
Sync sieve with problem-specifications (#1771)
Browse files Browse the repository at this point in the history
[no important files changed]
  • Loading branch information
senekor authored Nov 14, 2023
1 parent 0ed4c08 commit 532fffe
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 14 deletions.
2 changes: 1 addition & 1 deletion exercises/practice/sieve/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@
},
"blurb": "Use the Sieve of Eratosthenes to find all the primes from 2 up to a given number.",
"source": "Sieve of Eratosthenes at Wikipedia",
"source_url": "http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes"
"source_url": "https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes"
}
12 changes: 12 additions & 0 deletions exercises/practice/sieve/.meta/test_template.tera
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{% for test in cases %}
#[test]
{% if loop.index != 1 -%}
#[ignore]
{% endif -%}
fn {{ test.description | slugify | replace(from="-", to="_") }}() {
let input = {{ test.input.limit | json_encode() }};
let output = {{ crate_name }}::{{ fn_names[0] }}(input);
let expected = {{ test.expected | json_encode() }};
assert_eq!(output, expected);
}
{% endfor -%}
25 changes: 22 additions & 3 deletions exercises/practice/sieve/.meta/tests.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
# This is an auto-generated file. Regular comments will be removed when this
# file is regenerated. Regenerating will not touch any manually added keys,
# so comments can be added in a "comment" key.
# This is an auto-generated file.
#
# Regenerating this file via `configlet sync` will:
# - Recreate every `description` key/value pair
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion)
# - Preserve any other key/value pair
#
# As user-added comments (using the # character) will be removed when this file
# is regenerated, comments can be added via a `comment` key.

[88529125-c4ce-43cc-bb36-1eb4ddd7b44f]
description = "no primes under two"

[4afe9474-c705-4477-9923-840e1024cc2b]
description = "find first prime"

[974945d8-8cd9-4f00-9463-7d813c7f17b7]
description = "find primes up to 10"

[2e2417b7-3f3a-452a-8594-b9af08af6d82]
description = "limit is prime"

[92102a05-4c7c-47de-9ed0-b7d5fcd00f21]
description = "find primes up to 1000"
34 changes: 24 additions & 10 deletions exercises/practice/sieve/tests/sieve.rs
Original file line number Diff line number Diff line change
@@ -1,30 +1,44 @@
#[test]
fn limit_lower_than_the_first_prime() {
assert_eq!(sieve::primes_up_to(1), []);
fn no_primes_under_two() {
let input = 1;
let output = sieve::primes_up_to(input);
let expected = [];
assert_eq!(output, expected);
}

#[test]
#[ignore]
fn limit_is_the_first_prime() {
assert_eq!(sieve::primes_up_to(2), [2]);
fn find_first_prime() {
let input = 2;
let output = sieve::primes_up_to(input);
let expected = [2];
assert_eq!(output, expected);
}

#[test]
#[ignore]
fn primes_up_to_10() {
assert_eq!(sieve::primes_up_to(10), [2, 3, 5, 7]);
fn find_primes_up_to_10() {
let input = 10;
let output = sieve::primes_up_to(input);
let expected = [2, 3, 5, 7];
assert_eq!(output, expected);
}

#[test]
#[ignore]
fn limit_is_prime() {
assert_eq!(sieve::primes_up_to(13), [2, 3, 5, 7, 11, 13]);
let input = 13;
let output = sieve::primes_up_to(input);
let expected = [2, 3, 5, 7, 11, 13];
assert_eq!(output, expected);
}

#[test]
#[ignore]
fn limit_of_1000() {
let expected = vec![
fn find_primes_up_to_1000() {
let input = 1000;
let output = sieve::primes_up_to(input);
let expected = [
2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89,
97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181,
191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281,
Expand All @@ -35,5 +49,5 @@ fn limit_of_1000() {
751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863,
877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997,
];
assert_eq!(sieve::primes_up_to(1000), expected);
assert_eq!(output, expected);
}

0 comments on commit 532fffe

Please sign in to comment.