Created
May 13, 2020 23:49
-
-
Save riftrsps/24883db156fa14b27fd36bd9eb9fb43a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Player { | |
public boolean first; | |
public boolean second; | |
Player(boolean first, boolean second) { | |
this.first = first; | |
this.second = second; | |
} | |
@Override | |
public boolean equals(Object o) { | |
if (this == o) return true; | |
if (o == null || getClass() != o.getClass()) return false; | |
Player player = (Player) o; | |
return first == player.first && | |
second == player.second; | |
} | |
@Override | |
public int hashCode() { | |
return Objects.hash(first, second); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Scratch { | |
public static void main(String[] args) { | |
testAgainst(true, true); | |
testAgainst(true, false); | |
testAgainst(false, true); | |
testAgainst(false, false); | |
} | |
static void testAgainst(boolean originalForce, boolean originalUsing) { | |
Player mock1 = new Player(originalForce, originalUsing); | |
Player mock2 = new Player(originalForce, originalUsing); | |
Player mock3 = new Player(originalForce, originalUsing); | |
boolean result1 = original(mock1); | |
boolean result2 = clive(mock2); | |
boolean result3 = solution(mock3); | |
boolean equalResult = result1 == result2; | |
boolean equalMutation = mock1.equals(mock2); | |
System.out.println(String.format("TEST[%s,%s] SAME RETURN[%s] SAME MUTATION[%s]", originalForce, originalUsing, equalResult, equalMutation)); | |
} | |
public static boolean clive(Player player) { | |
if (player.second) { | |
player.first = false; | |
return true; | |
} | |
player.first = false; | |
player.second = true; | |
return false; | |
} | |
public static boolean original(Player player) { | |
if (player.first && player.second) { | |
player.first = false; | |
return true; | |
} | |
if (player.second) { | |
return true; | |
} | |
player.first = false; | |
player.second = true; | |
return false; | |
} | |
public static boolean solution(Player player) { | |
player.first = false; | |
if (player.second) | |
return true; | |
player.second = true; | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment