Templates for resistor-color exercises

attn @IsaacG

I found it odd that each of the first three in the series want a function called “color_code”. I’d like to contribute some templates.

I’m writing a template for resistor-color, and I notice the quote filter doesn’t seem to add quotes: am I using it correctly?

    return [solution_script.{{ case["property"] | camel_to_snake }}({{ case["input"]["color"] | quote }}), {{ case["expected"] }}]

That renders like

    return [solution_script.color_code(white), 9]

camel_to_kebab functioned, but not quote.

FWIW the togdscript filter worked fine to quote the string.

1 Like

Yeah, the canonical property is “value”. That was my mistake when I added Resistor Color Duo and then someone continued the issue for Trio and Expert. Duo and Trio should probably be updated to use value to match upstream, and then Expert should be switched to value for consistency’s sake since I don’t believe Expert has been added upstream yet.

1 Like

I have my commits ready to PR, but I’ll wait for Isaac’s thoughts.

Changing the function name affects a handful of people:

exercise started completed
resistor-color-duo 5 5
resistor-color-trio 5 4
resistor-color-expert 3 3

What did you have in mind?

Most of the GDScript templates use a near-identical template, including func test_{{ case.func_name }}(solution_script): which uses the property for the function name. That would give color_code() for the first exercise, value() for the second and label() for the third.

Might that be worth changing in the problem specs?

The 5 solutions each is pretty low. I think it’s fine to change the function name.

That’s exactly what I propose: Comparing exercism:main...glennj:resistor-color-templates · exercism/gdscript · GitHub

I don’t understand: that’s already there.

Looks good to me.

The problem spec has 4(?) distinct properties for the 4 exercises: color_code, value, label, resistor_label. Should we pick on and use the same label (resistance or value?) across all four problem spec data sets?

Note, I’ve been using dot-notation in the Jinja templates over the Python dict lookup. case.input.value over case["input"]["value"].

replaced. Can I open a PR?

Absolutely!

Resistor color templates by glennj · Pull Request #202 · exercism/gdscript · GitHub

1 Like