Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

diamond: Sync tests and generate them with Tera #2017

Merged
merged 1 commit into from
Feb 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions exercises/practice/diamond/.meta/test_template.tera
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use diamond::*;

{% for test in cases %}
#[test]
#[ignore]
fn {{ test.description | make_ident }}() {
{#
rustfmt will inline array literals under a minimum length
For us that means up to letter E
We also exclude A to keep it inlined
#}
{%- if test.input.letter is matching("[B-D]") %}
#[rustfmt::skip]
{%- endif %}
assert_eq!(
get_diamond('{{ test.input.letter }}'),
vec![
{%- for line in test.expected %}
"{{ line }}"{% if test.expected | length > 1 %},{% endif %}
{%- endfor %}
]
);
}
{% endfor %}

28 changes: 25 additions & 3 deletions exercises/practice/diamond/.meta/tests.toml
Original file line number Diff line number Diff line change
@@ -1,3 +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.

[202fb4cc-6a38-4883-9193-a29d5cb92076]
description = "Degenerate case with a single 'A' row"

[bd6a6d78-9302-42e9-8f60-ac1461e9abae]
description = "Degenerate case with no row containing 3 distinct groups of spaces"

[af8efb49-14ed-447f-8944-4cc59ce3fd76]
description = "Smallest non-degenerate case with odd diamond side length"

[e0c19a95-9888-4d05-86a0-fa81b9e70d1d]
description = "Smallest non-degenerate case with even diamond side length"

[82ea9aa9-4c0e-442a-b07e-40204e925944]
description = "Largest possible diamond"
10 changes: 5 additions & 5 deletions exercises/practice/diamond/tests/diamond.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use diamond::*;

#[test]
fn a() {
fn degenerate_case_with_a_single_a_row() {
assert_eq!(get_diamond('A'), vec!["A"]);
}

#[test]
#[ignore]
fn b() {
fn degenerate_case_with_no_row_containing_3_distinct_groups_of_spaces() {
#[rustfmt::skip]
assert_eq!(
get_diamond('B'),
Expand All @@ -21,7 +21,7 @@ fn b() {

#[test]
#[ignore]
fn c() {
fn smallest_non_degenerate_case_with_odd_diamond_side_length() {
#[rustfmt::skip]
assert_eq!(
get_diamond('C'),
Expand All @@ -37,7 +37,7 @@ fn c() {

#[test]
#[ignore]
fn d() {
fn smallest_non_degenerate_case_with_even_diamond_side_length() {
#[rustfmt::skip]
assert_eq!(
get_diamond('D'),
Expand All @@ -55,7 +55,7 @@ fn d() {

#[test]
#[ignore]
fn e() {
fn largest_possible_diamond() {
assert_eq!(
get_diamond('Z'),
vec![
Expand Down