-
Notifications
You must be signed in to change notification settings - Fork 524
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sync prime-factors with problem-specifications (#1832)
- Loading branch information
Showing
3 changed files
with
122 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
use {{ crate_name }}::*; | ||
|
||
{% for test in cases %} | ||
#[test] | ||
{% if loop.index != 1 -%} | ||
#[ignore] | ||
{% endif -%} | ||
fn {{ test.description | slugify | replace(from="-", to="_") }}() { | ||
let factors = {{ fn_names[0] }}({{ test.input.value }}); | ||
let expected = {{ test.expected | json_encode() }}; | ||
assert_eq!(factors, 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,46 @@ | ||
# 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. | ||
|
||
[924fc966-a8f5-4288-82f2-6b9224819ccd] | ||
description = "no factors" | ||
|
||
[17e30670-b105-4305-af53-ddde182cb6ad] | ||
description = "prime number" | ||
|
||
[238d57c8-4c12-42ef-af34-ae4929f94789] | ||
description = "another prime number" | ||
|
||
[f59b8350-a180-495a-8fb1-1712fbee1158] | ||
description = "square of a prime" | ||
|
||
[756949d3-3158-4e3d-91f2-c4f9f043ee70] | ||
description = "product of first prime" | ||
|
||
[bc8c113f-9580-4516-8669-c5fc29512ceb] | ||
description = "cube of a prime" | ||
|
||
[7d6a3300-a4cb-4065-bd33-0ced1de6cb44] | ||
description = "product of second prime" | ||
|
||
[073ac0b2-c915-4362-929d-fc45f7b9a9e4] | ||
description = "product of third prime" | ||
|
||
[6e0e4912-7fb6-47f3-a9ad-dbcd79340c75] | ||
description = "product of first and second prime" | ||
|
||
[00485cd3-a3fe-4fbe-a64a-a4308fc1f870] | ||
description = "product of primes and non-primes" | ||
|
||
[02251d54-3ca1-4a9b-85e1-b38f4b0ccb91] | ||
description = "product of primes" | ||
|
||
[070cf8dc-e202-4285-aa37-8d775c9cd473] | ||
description = "factors include a large prime" |
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,42 +1,96 @@ | ||
use prime_factors::factors; | ||
use prime_factors::*; | ||
|
||
#[test] | ||
fn no_factors() { | ||
assert_eq!(factors(1), vec![]); | ||
let factors = factors(1); | ||
let expected = []; | ||
assert_eq!(factors, expected); | ||
} | ||
|
||
#[test] | ||
#[ignore] | ||
fn prime_number() { | ||
assert_eq!(factors(2), vec![2]); | ||
let factors = factors(2); | ||
let expected = [2]; | ||
assert_eq!(factors, expected); | ||
} | ||
|
||
#[test] | ||
#[ignore] | ||
fn another_prime_number() { | ||
let factors = factors(3); | ||
let expected = [3]; | ||
assert_eq!(factors, expected); | ||
} | ||
|
||
#[test] | ||
#[ignore] | ||
fn square_of_a_prime() { | ||
assert_eq!(factors(9), vec![3, 3]); | ||
let factors = factors(9); | ||
let expected = [3, 3]; | ||
assert_eq!(factors, expected); | ||
} | ||
|
||
#[test] | ||
#[ignore] | ||
fn product_of_first_prime() { | ||
let factors = factors(4); | ||
let expected = [2, 2]; | ||
assert_eq!(factors, expected); | ||
} | ||
|
||
#[test] | ||
#[ignore] | ||
fn cube_of_a_prime() { | ||
assert_eq!(factors(8), vec![2, 2, 2]); | ||
let factors = factors(8); | ||
let expected = [2, 2, 2]; | ||
assert_eq!(factors, expected); | ||
} | ||
|
||
#[test] | ||
#[ignore] | ||
fn product_of_second_prime() { | ||
let factors = factors(27); | ||
let expected = [3, 3, 3]; | ||
assert_eq!(factors, expected); | ||
} | ||
|
||
#[test] | ||
#[ignore] | ||
fn product_of_third_prime() { | ||
let factors = factors(625); | ||
let expected = [5, 5, 5, 5]; | ||
assert_eq!(factors, expected); | ||
} | ||
|
||
#[test] | ||
#[ignore] | ||
fn product_of_first_and_second_prime() { | ||
let factors = factors(6); | ||
let expected = [2, 3]; | ||
assert_eq!(factors, expected); | ||
} | ||
|
||
#[test] | ||
#[ignore] | ||
fn product_of_primes_and_non_primes() { | ||
assert_eq!(factors(12), vec![2, 2, 3]); | ||
let factors = factors(12); | ||
let expected = [2, 2, 3]; | ||
assert_eq!(factors, expected); | ||
} | ||
|
||
#[test] | ||
#[ignore] | ||
fn product_of_primes() { | ||
assert_eq!(factors(901_255), vec![5, 17, 23, 461]); | ||
let factors = factors(901255); | ||
let expected = [5, 17, 23, 461]; | ||
assert_eq!(factors, expected); | ||
} | ||
|
||
#[test] | ||
#[ignore] | ||
fn factors_include_large_prime() { | ||
assert_eq!(factors(93_819_012_551), vec![11, 9539, 894_119]); | ||
fn factors_include_a_large_prime() { | ||
let factors = factors(93819012551); | ||
let expected = [11, 9539, 894119]; | ||
assert_eq!(factors, expected); | ||
} |