Advertisement
And1

test

Mar 4th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. //////////////////////////////////test 1
  2.  
  3. import java.util.Scanner;
  4. import java.util.Set;
  5. import java.util.TreeSet;
  6.  
  7. public class EratostheneSieve {
  8. public static void main(String[] args) {
  9. Scanner in = new Scanner(System.in);
  10. final int n = in.nextInt();
  11.  
  12. Set<Integer> primes = new IntSparseSet(2, n+1) {{
  13. for (int i = 2; i <= n; i++) add(i);
  14. for (int i = 2; i*i <= n; i++) {
  15. if (contains(i)) {
  16. for (int j = i*i; j <= n; j += i) remove(j);
  17. }
  18. }
  19. }};
  20.  
  21. for (int x : new TreeSet<Integer>(primes)) {
  22. System.out.printf("%d ", x);
  23. }
  24. System.out.println();
  25. }
  26. }
  27.  
  28. ///////////////////////////////////////////////test 2
  29. import java.util.Set;
  30.  
  31. public class Test2 {
  32. public static void main(String[] args) {
  33. Set<Integer> a = new IntSparseSet(-100, 100) {{
  34. for (int i = -100; i < 100; i += 2) Assert.assertTrue(add(i));
  35. }};
  36.  
  37. for (int i = -100; i < 100; i += 2) {
  38. Assert.assertFalse(a.add(i));
  39. }
  40.  
  41. Assert.assertFalse(a.add(1000));
  42.  
  43. System.out.println("PASSED");
  44. }
  45. }
  46.  
  47. ///////////////////////////
  48.  
  49.  
  50. public class Assert {
  51. public static <T> void assertNull(T obj) {
  52. if (obj != null) report("expected null value");
  53. }
  54.  
  55. public static void assertTrue(boolean b) {
  56. if (!b) report("expected true value");
  57. }
  58.  
  59. public static void assertFalse(boolean b) {
  60. if (b) report("expected false value");
  61. }
  62.  
  63. public static <T> void assertEquals(T expected, T actual) {
  64. if (!expected.equals(actual)) report("" + expected + " expected, but " + actual + " found");
  65. }
  66.  
  67. public static <T extends Number> void assertEquals(T expected, T actual, double eps) {
  68. double a = expected.doubleValue(), b = actual.doubleValue();
  69. if (Math.abs(a-b) > eps) report("" + expected + " expected, but " + actual + " found");
  70. }
  71.  
  72. private static void report(String s) {
  73. System.out.println(s);
  74. System.exit(0);
  75. }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement