Skip to content

Commit

Permalink
nth-prime: sync (exercism#1908)
Browse files Browse the repository at this point in the history
[no important files changed]
  • Loading branch information
senekor authored Apr 24, 2024
1 parent 3938f78 commit d5121fb
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 8 deletions.
11 changes: 11 additions & 0 deletions exercises/practice/nth-prime/.meta/test_template.tera
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use nth_prime::*;

{% for test in cases %}
#[test]
#[ignore]
fn {{ test.description | snake_case }}() {
let output = nth({{ test.input.number - 1 }});
let expected = {{ test.expected | json_encode() }};
assert_eq!(output, expected);
}
{% endfor -%}
33 changes: 30 additions & 3 deletions exercises/practice/nth-prime/.meta/tests.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,30 @@
# 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.

[75c65189-8aef-471a-81de-0a90c728160c]
description = "first prime"

[2c38804c-295f-4701-b728-56dea34fd1a0]
description = "second prime"

[56692534-781e-4e8c-b1f9-3e82c1640259]
description = "sixth prime"

[fce1e979-0edb-412d-93aa-2c744e8f50ff]
description = "big prime"

[bd0a9eae-6df7-485b-a144-80e13c7d55b2]
description = "there is no zeroth prime"
include = false
comment = """
The zeroth prime was defined to be 2 (zero-based indexing).
Changing it now would be an unnecessary breaking change.
"""
18 changes: 13 additions & 5 deletions exercises/practice/nth-prime/tests/nth-prime.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,32 @@
use nth_prime as np;
use nth_prime::*;

#[test]
fn first_prime() {
assert_eq!(np::nth(0), 2);
let output = nth(0);
let expected = 2;
assert_eq!(output, expected);
}

#[test]
#[ignore]
fn second_prime() {
assert_eq!(np::nth(1), 3);
let output = nth(1);
let expected = 3;
assert_eq!(output, expected);
}

#[test]
#[ignore]
fn sixth_prime() {
assert_eq!(np::nth(5), 13);
let output = nth(5);
let expected = 13;
assert_eq!(output, expected);
}

#[test]
#[ignore]
fn big_prime() {
assert_eq!(np::nth(10_000), 104_743);
let output = nth(10000);
let expected = 104743;
assert_eq!(output, expected);
}

0 comments on commit d5121fb

Please sign in to comment.