Created
June 13, 2020 07:41
-
-
Save viveksb007/8f36f30c4e58d280aad3b9068aa19a3c to your computer and use it in GitHub Desktop.
StreamPost
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
import java.util.function.Predicate; | |
public class IsPerfectSquare implements Predicate<Integer> { | |
@Override | |
public boolean test(Integer x) { | |
return Math.floor(Math.sqrt(x)) == Math.sqrt(x); | |
} | |
} |
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
import org.testng.annotations.BeforeClass; | |
import org.testng.annotations.Test; | |
import static org.testng.Assert.assertFalse; | |
import static org.testng.Assert.assertTrue; | |
public class IsPerfectSquareTest { | |
private IsPerfectSquare isPerfectSquare; | |
@BeforeClass | |
public void setUp() { | |
isPerfectSquare = new IsPerfectSquare(); | |
} | |
@Test | |
public void shouldReturnTrueForPerfectSquare() { | |
assertTrue(isPerfectSquare.test(81)); | |
assertTrue(isPerfectSquare.test(36)); | |
} | |
@Test | |
public void shouldReturnFalseIfNumberIsNotPerfectSquare() { | |
assertFalse(isPerfectSquare.test(8)); | |
assertFalse(isPerfectSquare.test(15)); | |
} | |
} |
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
import java.util.function.Function; | |
public class MultiplyBy3 implements Function<Integer, Integer> { | |
@Override | |
public Integer apply(Integer x) { | |
return x * 3; | |
} | |
} |
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
import java.util.function.Predicate; | |
public class OddFilterIn implements Predicate<Integer> { | |
@Override | |
public boolean test(Integer x) { | |
return x % 2 != 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment