Ad
  • Custom User Avatar
  • Default User Avatar

    If you extend this Kata to allow for let's say 0 <= flats/sharps <= 25 and 100's of random tests, it would become more mature.

  • Custom User Avatar
  • Custom User Avatar

    just a note...

    Mmmmh, correct. I always thought that the @Test methods were instance methods of the same instance, and not creating different instances for each method... How weird... :o

    But the loop still stays more "DRY" and easier to maintain. ;)

  • Custom User Avatar

    closer, but still some problems. ;)

    • don't put your solution in the preloaded part, put it (as private method) in the test class
    • make the solution setup runnable (return null;)
    • random tests: .... xo wow... That's "a bit" random... Except that you'r doing all the tests with the very same value, so it's the same as having one single random test. x)

    Note: instead of designing different test methods for the fixed tests, you could:

    • either use one single method and use arrays and a loop to chain all the tests
    • or design automated tests (@Parametrized stuff and so on). But that's quite complex to set up correctly in java, so I'd avoid that for the moment, if I were you. ;)

    About the random tests: one single method with a loop inside:

    
        private SecureRandom rand = new SecureRandom();     // warning with the modifiers
        
        @Test public void randomTests() {
            for (int i=0 ; i<100 ; i++) {
                int r = rand.nextInt(150);
                assertEquals(expectedAttributes(r), Attributes.charAttribute(r));
            }
        }
        
        private Map<String,String> expectedAttributes(int r) {
            ...
        }
    
  • Custom User Avatar
    • Don't use actual implementations of classes as returned type, but interfaces => public static Map<String, String> charAttribute(int score) {.... This way, the user can use whatever he wants (for instance, why a linked hashmap? A simple hashmap is sufficient. But in either way, the returned type needs to be a Map).
    • Same for your testMap method. Use a Map for the argument.
    • seems like your IDE is using tabulations instead of whitespaces. CW's editor doesn't behave pretty well with that, as you can see (your identations or somewhat "wild", for now). => either you change the setup of your ide so that it uses only spaces and no tabulation chars ever, or in CW's editor (the translation panel): Ctrl+H -> replace: /\t/ -> with: ____ -> ALL (4 spaces instaed of the underscores, ofc)
    • (... what the... xo ) => your """random""" tests are absolutely not random. They are fixed! =) => you need to change that.
  • Default User Avatar

    If you have a problem with your code, mark a question instead of an issue.

    You need to deal with floating point inaccuracy.