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

Add dnd-character exercise #751

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Add dnd-character exercise #751

wants to merge 1 commit into from

Conversation

ErikSchierboom
Copy link
Member

No description provided.

@ErikSchierboom ErikSchierboom force-pushed the dnd-character branch 4 times, most recently from 4467bb9 to fbdc253 Compare January 15, 2025 13:26
Copy link
Member

@tasxatzial tasxatzial left a comment

Choose a reason for hiding this comment

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

It's very difficult to review this. It includes more tests than the canonical data, the descriptions don't seem to match the canonical data, and there are even tests like (>= (count (set (repeatedly 100 #(dnd-character/ability)))) 5), which I can't locate in the canonical data.

Extensive deviations from the canonical data make it very challenging to perform manual comparisons when something needs to be inspected.

Were there specific reasons for these deviations?

@ErikSchierboom
Copy link
Member Author

Were there specific reasons for these deviations?

Yes, because this an exercise which canonical data in large part describe "properties," not concrete test values. This is due to the fact that we're dealing with randomness, which doesn't fit well into the regular canonical data format.

It's very difficult to review this. It includes more tests than the canonical data, the descriptions don't seem to match the canonical data, and there are even tests like (>= (count (set (repeatedly 100 #(dnd-character/ability)))) 5), which I can't locate in the canonical data.
Extensive deviations from the canonical data make it very challenging to perform manual comparisons when something needs to be inspected.

I understand, but in this case I feel extra tests are warranted.
Take this test case, which is the only test case for the ability function:

{
      "uuid": "4f28f19c-2e47-4453-a46a-c0d365259c14",
      "description": "random ability is within range",
      "scenarios": ["random"],
      "property": "ability",
      "input": {},
      "expected": "score >= 3 && score <= 18"
    },

In essence, this is specifying two things:

  1. The resulting value should be between 3 and 18
  2. Each value is generated randomly

This is why the additional test is added. We could combine them into a single test, but I feel that a separate test makes more sense. Basically what I want to test is that the function does not keep on returning the same values, but that it is doing something random.

A similar argument applies to the tests for the character property:

{
      "uuid": "385d7e72-864f-4e88-8279-81a7d75b04ad",
      "description": "random character is valid",
      "scenarios": ["random"],
      "property": "character",
      "input": {},
      "expected": {
        "strength": "strength >= 3 && strength <= 18",
        "dexterity": "dexterity >= 3 && dexterity <= 18",
        "constitution": "constitution >= 3 && constitution <= 18",
        "intelligence": "intelligence >= 3 && intelligence <= 18",
        "wisdom": "wisdom >= 3 && wisdom <= 18",
        "charisma": "charisma >= 3 && charisma <= 18",
        "hitpoints": "hitpoints == 10 + modifier(constitution)"
      }
    }

As you can see, this test case actually has at least 7 different tests, and with the added test for random generation, we get 8 tests encoded by a single test case property.

@ErikSchierboom
Copy link
Member Author

@tasxatzial What do you think about naming the functions rand-ability and rand-character to be in line with what is in clojure.core?

@tasxatzial
Copy link
Member

My preference is to use verbs for function names, but I understand this can sometimes result in verbose names. As such, I'm not too particular about naming. I don't believe the official documentation strictly follows this guideline either.

In my view, reasons to switch from ability to rand-ability would be:

  • It's a bit more specific.
  • It's longer, which makes it less likely for people to reuse it as a variable inside the function. By switching, it becomes possible to use a variable named ability and return it as the final step.

@ErikSchierboom
Copy link
Member Author

Okay. I've updated the PR

@tasxatzial
Copy link
Member

tasxatzial commented Jan 17, 2025

Couple extra suggestions before i do a proper review:

  • Let's rename the function from modifier to score-modifier
  • Template file needs to be updated with new changes:
    • modifier -> score-modifier
    • character -> rand-character
    • ability -> rand-ability
  • Separate parent/child descriptions with >> (i prefer the ) instead of -

@ErikSchierboom
Copy link
Member Author

Separate parent/child descriptions with >> (i prefer the ▶) instead of -

Is this something that you would like to see changed for all exercises?

@ErikSchierboom
Copy link
Member Author

I've updated

@ErikSchierboom
Copy link
Member Author

@tasxatzial I've created a PR to update the separator: #779 Let's get that merged first and then I'll update this PR

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