Skip to content

Conversation

khalidbelk
Copy link
Contributor

Hi :) ! Here's a port of the D&D character practice exercise (currently not implemented in the OCaml track). Let me know if there's something missing ; )

We don't really mutate state. Fixes the type mismatching issue between example.ml and the exercise's provided .mli file.
The tests were implemented by hand following the specification. The rest of automatic files via configlet because of the make commands not generating the exercises/ subdirectory
@khalidbelk
Copy link
Contributor Author

@kahgoh could you take a look at this please : ) ?

Copy link
Member

@kahgoh kahgoh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At a glance, this generally looks ok and there are some minor comments below. However, the OCaml track also uses a test generator to generate the tests from the problem specifications. Would you like to try creating one for D&D character?

@khalidbelk
Copy link
Contributor Author

At a glance, this generally looks ok and there are some minor comments below. However, the OCaml track also uses a test generator to generate the tests from the problem specifications. Would you like to try creating one for D&D character?

The thing is that I initially tried to generate them from a .tpl file but it's a little bit tricky for this exercise, something like the following example will never reach the description fields inside the nested cases array, since the D&D specification structure is kinda inconsistent (uses a nested cases array of objects for the first tests, and then objects that don't follow the same structure), which either causes it to ignore those objects or fails when it doesn't meet an expected field.

...
let tests = [
  {{#cases}}
    {{#cases}}
      "{{description}}" >::
        ae 1 2
    {{/cases}}
  {{/cases}}
]
...

After looking into it a bit more last night I found that it might be possible to preprocess the JSON before the test generator passes it to mustache to avoid those types of errors. Can you confirm that's what it's used for?
I can take a look at it when I have some time :)

@khalidbelk khalidbelk requested a review from kahgoh September 30, 2025 19:48
@kahgoh
Copy link
Member

kahgoh commented Oct 1, 2025

After looking into it a bit more last night I found that it might be possible to preprocess the JSON before the test generator passes it to mustache to avoid those types of errors. Can you confirm that's what it's used for?

Yes, that's right! You can use the special cases to pre-process the JSON as needed.

Copy link
Member

@kahgoh kahgoh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes from your last set of commits look good. Just waiting to see how you go with the test template.

@khalidbelk
Copy link
Contributor Author

The changes from your last set of commits look good. Just waiting to see how you go with the test template.

Thanks for being active ! I didn't really have time to keep you updated 😅.

I've been investigating further and I think there's no way to just generate all the tests correctly via the generator in the current state of the files, unless:

    1. The spec JSON is modified (which could potentially break other generators).
    1. This part of the generator is "modified" to handle these type of complex cases (which obviously isn't a viable option for an issue related to only 1 exercise)

This is because the errors happen in the case-sanitizing step, so before the contents can reach the edit_parameters section.

So, long story short : the issue here is caused by the incompatibility between the inconsistent spec's JSON, and the way the OCaml test generator handles it (not really its fault since it is made to handle consistent JSON's), which prevents those cases from being extracted.

For other exercises, even if they have multiple levels of indentation / multiple cases, they don't have any issues because their spec is consistent. For example see this spec , and its template.

Copy link
Member

@kahgoh kahgoh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I think we can still go ahead for now. Thanks for looking into the test template!

@kahgoh kahgoh merged commit 7583cbc into exercism:main Oct 2, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants