#JAVA Annalyn's Infiltration

2 messages · Page 1 of 1 (latest)

wide sail
#
class AnnalynsInfiltration {
    public static boolean canFastAttack(boolean knightIsAwake) {
        return !knightIsAwake;
    }

    public static boolean canSpy(boolean knightIsAwake, boolean archerIsAwake, boolean prisonerIsAwake) {
        return knightIsAwake || archerIsAwake || prisonerIsAwake;
    }

    public static boolean canSignalPrisoner(boolean archerIsAwake, boolean prisonerIsAwake) {
        return !archerIsAwake && prisonerIsAwake;
    }

    public static boolean canFreePrisoner(boolean knightIsAwake, boolean archerIsAwake, boolean prisonerIsAwake, boolean petDogIsPresent) {
        return knightIsAwake && archerIsAwake && prisonerIsAwake && petDogIsPresent;
    }
}

The other functions work fine, but the canFreePrisoner(boolean knightIsAwake, boolean archerIsAwake, boolean prisonerIsAwake, boolean petDogIsPresent) function continues to throw an error in the many test cases. How should I modify my code?

example case
Message:
Expecting value to be false but was true
Exception: org.opentest4j.AssertionFailedError:
Expecting value to be false but was true
at java.base/jdk.internal.reflect.DirectConstructorHandleAccessor.newInstance(DirectConstructorHandleAccessor.java:62)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:502)
at AnnalynsInfiltrationTest.cannot_release_prisoner_if_everyone_is_awake_and_pet_dog_is_present(AnnalynsInfiltrationTest.java:150)
at java.base/java.lang.reflect.Method.invoke(Method.java:580)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)

hot stream
#
  • Do you understand the task, what canFreePrisoner is supposed to do?
  • Do you understand why this test named cannot_release_prisoner_if_everyone_is_awake_and_pet_dog_is_present requires the function to return false?
  • Do you understand why with your implementation the function callcanFreePrisoner(true, true, true, true) returns true?