Ad
  • Custom User Avatar

    Yea, looking back at this and what I implemented was not great. Haha. I have refactored the code such that it only references the function and removed all that companion object stuff. Also I removed the complicated tests and just left a simple test that expects given inputs and expected outcomes. Let me know what you think. Thanks

  • Custom User Avatar

    Kotlin Translation kumited. Please review and approve if all is well with thee.

  • Custom User Avatar

    For Kotlin, could you make some changes to the test Class and remove the semicolons and also the unused import import java.util.Random. I noticed that if I copy and paste with the semicolon, some IDEs will think it is a Java Class rather than a Kotlin Class.
    I've put the edit below:

    import org.junit.Test
    import kotlin.test.assertEquals
    
    class OppositeExampleTests {
    
      @Test fun testFixed() {
        assertEquals(-1, opposite(1))
        assertEquals(0, opposite(0))
        assertEquals(25, opposite(-25))
      }
    }
    
  • Custom User Avatar

    For Java, the method signature should be:

      public static int sumOfAngles(int n) {
          // Code Here
      }
    

    yours is void and won't return anything.
    You unit tests should take the format of assertEquals('expected value here', AngleSum.sumOfAngles(3));

  • Custom User Avatar

    Also the parameter should specify the type which is int. currently it's public int nearestSq(n){} when it should be public static int nearestSq(int n){}

  • Custom User Avatar

    Your tests are in the wrong format: org.junit.Assert.assertEquals("expected", "actual");. You have this the other way around.

  • Custom User Avatar

    Your tests are the wrong way round they should follow this format assertArrayEquals(int[] expected, int[] actual);.
    Your tests are the other way round in this case:

    assertArrayEquals(new String[]{ "tail", "body", "head" },
              WrongEndHead.fixTheMeerkat(new String[]{ "head", "body", "tail" }));
    

    which is not consistent to what you said: You will be given an array which will have three values (tail, body, head). It is your job to re-arrange the array so that the animal is the right way round (head, body, tail).. You're passing the correct values to the fixTheMeerkat() method.