|
| 1 | +package com.codewars.chrisgw.algorithms.kyu_4; |
| 2 | + |
| 3 | +import org.junit.jupiter.api.Test; |
| 4 | + |
| 5 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 6 | + |
| 7 | +/** |
| 8 | + * <h2>Create a funnel</h2> |
| 9 | + * <a href="https://www.codewars.com/kata/585b373ce08bae41b800006e">https://www.codewars.com/kata/585b373ce08bae41b800006e</a> |
| 10 | + */ |
| 11 | +class CreateAFunnelTest { |
| 12 | + |
| 13 | + String SETUP = "\n\n-----------------------------------\n"; |
| 14 | + String TEARDOWN = "\n"; |
| 15 | + |
| 16 | + @Test |
| 17 | + public void basicTests() { |
| 18 | + |
| 19 | + CreateAFunnel funnel = new CreateAFunnel(); |
| 20 | + String now = ""; |
| 21 | + Character dropped = null; |
| 22 | + |
| 23 | + System.out.println(SETUP + "Creating an empty funnel" + TEARDOWN); |
| 24 | + |
| 25 | + now = "\\ /\n" + |
| 26 | + " \\ /\n" + |
| 27 | + " \\ /\n" + |
| 28 | + " \\ /\n" + |
| 29 | + " \\ /"; |
| 30 | + System.out.println("Funnel should be now:\n" + now); |
| 31 | + assertEquals(now, funnel.toString()); |
| 32 | + |
| 33 | + |
| 34 | + System.out.println(SETUP + "Testing the fill method" + TEARDOWN); |
| 35 | + |
| 36 | + funnel.fill('1', '2', '3'); |
| 37 | + now = ("\\ /\n" + |
| 38 | + " \\ /\n" + |
| 39 | + " \\ /\n" + |
| 40 | + " \\2 3/\n" + |
| 41 | + " \\1/"); |
| 42 | + |
| 43 | + System.out.println("Funnel should be now:\n" + now); |
| 44 | + assertEquals(now, funnel.toString()); |
| 45 | + |
| 46 | + |
| 47 | + System.out.println(SETUP + "Testing the drip method" + TEARDOWN); |
| 48 | + |
| 49 | + dropped = funnel.drip(); |
| 50 | + now = ("\\ /\n" + |
| 51 | + " \\ /\n" + |
| 52 | + " \\ /\n" + |
| 53 | + " \\ 3/\n" + |
| 54 | + " \\2/"); |
| 55 | + |
| 56 | + System.out.println("Funnel should be now:\n" + now); |
| 57 | + assertEquals(now, funnel.toString()); |
| 58 | + assertEquals(Character.valueOf('1'), dropped, "The drip method should return the value at the bottom of the funnel"); |
| 59 | + |
| 60 | + |
| 61 | + System.out.println(SETUP + "Testing the fill functions with gaps and excess" + TEARDOWN); |
| 62 | + |
| 63 | + funnel.fill('4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'); |
| 64 | + now = ("\\C D E F G/\n" + |
| 65 | + " \\8 9 A B/\n" + |
| 66 | + " \\5 6 7/\n" + |
| 67 | + " \\4 3/\n" + |
| 68 | + " \\2/"); |
| 69 | + |
| 70 | + System.out.println("Funnel should be now:\n" + now); |
| 71 | + assertEquals(now, funnel.toString()); |
| 72 | + } |
| 73 | + |
| 74 | + |
| 75 | + @Test |
| 76 | + public void exampleTests() { |
| 77 | + CreateAFunnel funnel = new CreateAFunnel(); |
| 78 | + String now = ""; |
| 79 | + Character dropped = null; |
| 80 | + |
| 81 | + funnel.fill('1', '2', '3', '4', '5', '6', '7', '8', '9'); |
| 82 | + now = ("\\ /\n" + |
| 83 | + " \\7 8 9 /\n" + |
| 84 | + " \\4 5 6/\n" + |
| 85 | + " \\2 3/\n" + |
| 86 | + " \\1/"); |
| 87 | + |
| 88 | + System.out.println("Funnel should be now:\n" + now); |
| 89 | + assertEquals(now, funnel.toString()); |
| 90 | + |
| 91 | + |
| 92 | + System.out.println(SETUP + "Testing the drip method" + TEARDOWN); |
| 93 | + |
| 94 | + dropped = funnel.drip(); |
| 95 | + now = ("\\ /\n" + |
| 96 | + " \\ 8 9 /\n" + |
| 97 | + " \\7 5 6/\n" + |
| 98 | + " \\4 3/\n" + |
| 99 | + " \\2/"); |
| 100 | + |
| 101 | + System.out.println("Funnel should be now:\n" + now); |
| 102 | + assertEquals(now, funnel.toString()); |
| 103 | + assertEquals(Character.valueOf('1'), dropped, "The drip method should return the value at the bottom of the funnel"); |
| 104 | + |
| 105 | + |
| 106 | + System.out.println(SETUP + "Testing the fill functions with gaps and excess" + TEARDOWN); |
| 107 | + |
| 108 | + dropped = funnel.drip(); |
| 109 | + now = "\\ /\n" + |
| 110 | + " \\ 9 /\n" + |
| 111 | + " \\7 8 6/\n" + |
| 112 | + " \\5 3/\n" + |
| 113 | + " \\4/"; |
| 114 | + |
| 115 | + System.out.println("Funnel should be now:\n" + now); |
| 116 | + assertEquals(now, funnel.toString()); |
| 117 | + assertEquals(Character.valueOf('2'), dropped, "The drip method should return the value at the bottom of the funnel"); |
| 118 | + |
| 119 | + |
| 120 | + dropped = funnel.drip(); |
| 121 | + now = "\\ /\n" + |
| 122 | + " \\ /\n" + |
| 123 | + " \\7 9 6/\n" + |
| 124 | + " \\8 3/\n" + |
| 125 | + " \\5/"; |
| 126 | + |
| 127 | + System.out.println("Funnel should be now:\n" + now); |
| 128 | + assertEquals(now, funnel.toString()); |
| 129 | + assertEquals(Character.valueOf('4'), dropped, "The drip method should return the value at the bottom of the funnel"); |
| 130 | + } |
| 131 | + |
| 132 | +} |
0 commit comments