|
| 1 | +import { assert } from 'chai'; |
| 2 | +import sinon from 'sinon'; |
| 3 | +import File from '../../../../File.js'; |
| 4 | +import { execute } from '../../../../../lib/community/training/medium/rearrangeStringToTwoNumbers/rearrangeStringToTwoNumbers.js'; |
| 5 | + |
| 6 | +const __dirname = new URL('.', import.meta.url).pathname; |
| 7 | + |
| 8 | +suite("Rearrange string to two numbers", function() { |
| 9 | + const sandbox = sinon.createSandbox(); |
| 10 | + |
| 11 | + setup(function () { |
| 12 | + sandbox.stub(console, "log"); |
| 13 | + }); |
| 14 | + |
| 15 | + teardown(function () { |
| 16 | + sandbox.restore(); |
| 17 | + }); |
| 18 | + |
| 19 | + |
| 20 | + test("Two digits", function() { |
| 21 | + let inputFile = new File(__dirname + 'input/01 - two digits.txt'); |
| 22 | + |
| 23 | + execute(inputFile.readline.bind(inputFile)); |
| 24 | + |
| 25 | + assert.strictEqual( |
| 26 | + console.log.getCall(0).args[0], |
| 27 | + "2 7" |
| 28 | + ); |
| 29 | + }); |
| 30 | + |
| 31 | + test("Too many digits", function() { |
| 32 | + let inputFile = new File(__dirname + 'input/02 - too many digits.txt'); |
| 33 | + |
| 34 | + execute(inputFile.readline.bind(inputFile)); |
| 35 | + |
| 36 | + assert.strictEqual( |
| 37 | + console.log.getCall(0).args[0], |
| 38 | + "-1 -1" |
| 39 | + ); |
| 40 | + }); |
| 41 | + |
| 42 | + test("Maximum B", function() { |
| 43 | + let inputFile = new File(__dirname + 'input/03 - maximum B.txt'); |
| 44 | + |
| 45 | + execute(inputFile.readline.bind(inputFile)); |
| 46 | + |
| 47 | + assert.strictEqual( |
| 48 | + console.log.getCall(0).args[0], |
| 49 | + "400005555567778999 1000000000000000000" |
| 50 | + ); |
| 51 | + }); |
| 52 | + |
| 53 | + test("Too many 0's", function() { |
| 54 | + let inputFile = new File(__dirname + 'input/04 - too many 0s.txt'); |
| 55 | + |
| 56 | + execute(inputFile.readline.bind(inputFile)); |
| 57 | + |
| 58 | + assert.strictEqual( |
| 59 | + console.log.getCall(0).args[0], |
| 60 | + "-1 -1" |
| 61 | + ); |
| 62 | + }); |
| 63 | + |
| 64 | + test("Maximum B with 0", function() { |
| 65 | + let inputFile = new File(__dirname + 'input/05 - maximum B with 0.txt'); |
| 66 | + |
| 67 | + execute(inputFile.readline.bind(inputFile)); |
| 68 | + |
| 69 | + assert.strictEqual( |
| 70 | + console.log.getCall(0).args[0], |
| 71 | + "0 1000000000000000000" |
| 72 | + ); |
| 73 | + }); |
| 74 | + |
| 75 | + test("Small A maximum B", function() { |
| 76 | + let inputFile = new File(__dirname + 'input/06 - small A maximum B.txt'); |
| 77 | + |
| 78 | + execute(inputFile.readline.bind(inputFile)); |
| 79 | + |
| 80 | + assert.strictEqual( |
| 81 | + console.log.getCall(0).args[0], |
| 82 | + "4 1000000000000000000" |
| 83 | + ); |
| 84 | + }); |
| 85 | + |
| 86 | + test("Small A big B", function() { |
| 87 | + let inputFile = new File(__dirname + 'input/07 - small A big B.txt'); |
| 88 | + |
| 89 | + execute(inputFile.readline.bind(inputFile)); |
| 90 | + |
| 91 | + assert.strictEqual( |
| 92 | + console.log.getCall(0).args[0], |
| 93 | + "20 200223334577788999" |
| 94 | + ); |
| 95 | + }); |
| 96 | + |
| 97 | + test("Too many 0's", function() { |
| 98 | + let inputFile = new File(__dirname + 'input/08 - too many 0s - 2.txt'); |
| 99 | + |
| 100 | + execute(inputFile.readline.bind(inputFile)); |
| 101 | + |
| 102 | + assert.strictEqual( |
| 103 | + console.log.getCall(0).args[0], |
| 104 | + "-1 -1" |
| 105 | + ); |
| 106 | + }); |
| 107 | + |
| 108 | + test("Too few digits", function() { |
| 109 | + let inputFile = new File(__dirname + 'input/09 - too few digits.txt'); |
| 110 | + |
| 111 | + execute(inputFile.readline.bind(inputFile)); |
| 112 | + |
| 113 | + assert.strictEqual( |
| 114 | + console.log.getCall(0).args[0], |
| 115 | + "-1 -1" |
| 116 | + ); |
| 117 | + }); |
| 118 | + |
| 119 | + test("Too many digits", function() { |
| 120 | + let inputFile = new File(__dirname + 'input/10 - too many digits.txt'); |
| 121 | + |
| 122 | + execute(inputFile.readline.bind(inputFile)); |
| 123 | + |
| 124 | + assert.strictEqual( |
| 125 | + console.log.getCall(0).args[0], |
| 126 | + "-1 -1" |
| 127 | + ); |
| 128 | + }); |
| 129 | + |
| 130 | + test("Zero", function() { |
| 131 | + let inputFile = new File(__dirname + 'input/11 - zero.txt'); |
| 132 | + |
| 133 | + execute(inputFile.readline.bind(inputFile)); |
| 134 | + |
| 135 | + assert.strictEqual( |
| 136 | + console.log.getCall(0).args[0], |
| 137 | + "0 400004566667788899" |
| 138 | + ); |
| 139 | + }); |
| 140 | + |
| 141 | + test("Maximum", function() { |
| 142 | + let inputFile = new File(__dirname + 'input/12 - maximum.txt'); |
| 143 | + |
| 144 | + execute(inputFile.readline.bind(inputFile)); |
| 145 | + |
| 146 | + assert.strictEqual( |
| 147 | + console.log.getCall(0).args[0], |
| 148 | + "1000000000000000000 1000000000000000000" |
| 149 | + ); |
| 150 | + }); |
| 151 | + |
| 152 | + test("Big with 0's", function() { |
| 153 | + let inputFile = new File(__dirname + 'input/13 - big with 0s.txt'); |
| 154 | + |
| 155 | + execute(inputFile.readline.bind(inputFile)); |
| 156 | + |
| 157 | + assert.strictEqual( |
| 158 | + console.log.getCall(0).args[0], |
| 159 | + "200000222233333345 566777777888999999" |
| 160 | + ); |
| 161 | + }); |
| 162 | + |
| 163 | + test("Big", function() { |
| 164 | + let inputFile = new File(__dirname + 'input/14 - big.txt'); |
| 165 | + |
| 166 | + execute(inputFile.readline.bind(inputFile)); |
| 167 | + |
| 168 | + assert.strictEqual( |
| 169 | + console.log.getCall(0).args[0], |
| 170 | + "111112222333355566 777778888889999999" |
| 171 | + ); |
| 172 | + }); |
| 173 | + |
| 174 | + test("Internal zeros", function() { |
| 175 | + let inputFile = new File(__dirname + 'input/15 - internal zeros.txt'); |
| 176 | + |
| 177 | + execute(inputFile.readline.bind(inputFile)); |
| 178 | + |
| 179 | + assert.strictEqual( |
| 180 | + console.log.getCall(0).args[0], |
| 181 | + "100022233334444 45555555666668899" |
| 182 | + ); |
| 183 | + }); |
| 184 | + |
| 185 | + test("Small A big B", function() { |
| 186 | + let inputFile = new File(__dirname + 'input/16 - small A big B.txt'); |
| 187 | + |
| 188 | + execute(inputFile.readline.bind(inputFile)); |
| 189 | + |
| 190 | + assert.strictEqual( |
| 191 | + console.log.getCall(0).args[0], |
| 192 | + "5 555566666667778899" |
| 193 | + ); |
| 194 | + }); |
| 195 | + |
| 196 | + test("Small A big B", function() { |
| 197 | + let inputFile = new File(__dirname + 'input/17 - small A big B - 2.txt'); |
| 198 | + |
| 199 | + execute(inputFile.readline.bind(inputFile)); |
| 200 | + |
| 201 | + assert.strictEqual( |
| 202 | + console.log.getCall(0).args[0], |
| 203 | + "4 44455566667788" |
| 204 | + ); |
| 205 | + }); |
| 206 | + |
| 207 | + test("Two digits", function() { |
| 208 | + let inputFile = new File(__dirname + 'input/18 - two digits.txt'); |
| 209 | + |
| 210 | + execute(inputFile.readline.bind(inputFile)); |
| 211 | + |
| 212 | + assert.strictEqual( |
| 213 | + console.log.getCall(0).args[0], |
| 214 | + "9 9" |
| 215 | + ); |
| 216 | + }); |
| 217 | +}); |
0 commit comments