Giter Club home page Giter Club logo

Comments (5)

umuser avatar umuser commented on June 14, 2024 1

I would like to fix this, but I found another problem with the tests. Calculating abilities does not test that 3 largest numbers are used as the exercise description says

...You do this by rolling four 6-sided dice and record the sum of the largest three dice

For example, some solutions contain code like this new Random().ints(4, 1, 7).sorted().limit(3).sum();, but .sorted() sorts in ascending order so the sum of the smallest numbers is returned.

Maybe a solution could be that throwing dice is refactored into its own function that returns a list of 4 numbers. Also, the ability function should then be changed to take a list of 4 numbers as input. This way ability calculation can be tested with certain input and expected results.

List<Integer> throwDice() {..}

int ability(List<Integer> diceValues) {..}

@Test
public void testAbilityCalculation() {
    assertEquals(9, dndCharacter.ability(List.of(1,2,3,4)));
}

from java.

andrerfcsantos avatar andrerfcsantos commented on June 14, 2024

Thanks for reporting this!

This is indeed an issue with the lack of tests.

keeping a copy of the first character and making sure that at least one of the 1000 other generated characters is different. Without actually trying to do the calculations, the chance of generating 1000 identical characters should be sufficiently zero to not be concerned about false negatives.

I agree with this solution, anyone is welcome to submit a PR for it! However, I don't think we need 1000 iterations, maybe 100, 500 max is enough?

from java.

ChrisCookOC avatar ChrisCookOC commented on June 14, 2024

Re: 1000 - that suggests mainly comes from the fact it already does an iteration of 1000

@umuser - that's a good spot too! Certainly would be happy with ability taking in a List as a solution to that, although I wouldn't necessarily mandate that you use a throwDice function defined as such? It's probably the nicest way to do it, but since we won't be testing the throwDice method directly we should just let it be defined privately however people want?

from java.

andrerfcsantos avatar andrerfcsantos commented on June 14, 2024

@umuser Feel free to submit a PR fixing that problem too.

I think it's reasonable to have ability take a list as an argument, and I'm also ok with having a throwDice function defined like that. However, if adding such function, we should add tests for that function too.

from java.

andrerfcsantos avatar andrerfcsantos commented on June 14, 2024

PR #2218 has been merged.

from java.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.