|
| 1 | +import { assert } from 'chai'; |
| 2 | +import sinon from 'sinon'; |
| 3 | +import File from '../../../../File.js'; |
| 4 | +import { assertOutputAnswer } from '../../../../assertOutputAnswer.js'; |
| 5 | +import { execute } from '../../../../../lib/community/training/medium/advancedTree/advancedTree.js'; |
| 6 | + |
| 7 | +const __dirname = new URL('.', import.meta.url).pathname; |
| 8 | + |
| 9 | +suite("Advanced tree", function() { |
| 10 | + const sandbox = sinon.createSandbox(); |
| 11 | + |
| 12 | + setup(function () { |
| 13 | + sandbox.stub(console, "log"); |
| 14 | + }); |
| 15 | + |
| 16 | + teardown(function () { |
| 17 | + sandbox.restore(); |
| 18 | + }); |
| 19 | + |
| 20 | + |
| 21 | + test("Example", function() { |
| 22 | + let inputFile = new File(__dirname + 'input/01 - example.txt'); |
| 23 | + |
| 24 | + execute(inputFile.readline.bind(inputFile)); |
| 25 | + |
| 26 | + assertOutputAnswer(__dirname + 'output/01 - example.txt'); |
| 27 | + }); |
| 28 | + |
| 29 | + test("In a directory test", function() { |
| 30 | + let inputFile = new File(__dirname + 'input/02 - in a directory test.txt'); |
| 31 | + |
| 32 | + execute(inputFile.readline.bind(inputFile)); |
| 33 | + |
| 34 | + assertOutputAnswer(__dirname + 'output/02 - in a directory test.txt'); |
| 35 | + }); |
| 36 | + |
| 37 | + test("Also in a directory test", function() { |
| 38 | + let inputFile = new File(__dirname + 'input/03 - also in a directory test.txt'); |
| 39 | + |
| 40 | + execute(inputFile.readline.bind(inputFile)); |
| 41 | + |
| 42 | + assertOutputAnswer(__dirname + 'output/03 - also in a directory test.txt'); |
| 43 | + }); |
| 44 | + |
| 45 | + test("Gap end of tree handling test", function() { |
| 46 | + let inputFile = new File(__dirname + 'input/04 - gap end of tree handling test.txt'); |
| 47 | + |
| 48 | + execute(inputFile.readline.bind(inputFile)); |
| 49 | + |
| 50 | + assertOutputAnswer(__dirname + 'output/04 - gap end of tree handling test.txt'); |
| 51 | + }); |
| 52 | + |
| 53 | + test("Hidden directories w/o -a test", function() { |
| 54 | + let inputFile = new File(__dirname + 'input/05 - hidden directories wo -a test.txt'); |
| 55 | + |
| 56 | + execute(inputFile.readline.bind(inputFile)); |
| 57 | + |
| 58 | + assertOutputAnswer(__dirname + 'output/05 - hidden directories wo -a test.txt'); |
| 59 | + }); |
| 60 | + |
| 61 | + test("Dots in filenames test", function() { |
| 62 | + let inputFile = new File(__dirname + 'input/06 - dots in filenames test.txt'); |
| 63 | + |
| 64 | + execute(inputFile.readline.bind(inputFile)); |
| 65 | + |
| 66 | + assertOutputAnswer(__dirname + 'output/06 - dots in filenames test.txt'); |
| 67 | + }); |
| 68 | + |
| 69 | + test("Limit flag test", function() { |
| 70 | + let inputFile = new File(__dirname + 'input/07 - limit flag test.txt'); |
| 71 | + |
| 72 | + execute(inputFile.readline.bind(inputFile)); |
| 73 | + |
| 74 | + assertOutputAnswer(__dirname + 'output/07 - limit flag test.txt'); |
| 75 | + }); |
| 76 | + |
| 77 | + test("Hidden files w/o -a test", function() { |
| 78 | + let inputFile = new File(__dirname + 'input/08 - hidden files wo -a test.txt'); |
| 79 | + |
| 80 | + execute(inputFile.readline.bind(inputFile)); |
| 81 | + |
| 82 | + assertOutputAnswer(__dirname + 'output/08 - hidden files wo -a test.txt'); |
| 83 | + }); |
| 84 | + |
| 85 | + test("Hidden files with -a test", function() { |
| 86 | + let inputFile = new File(__dirname + 'input/09 - hidden files with -a test.txt'); |
| 87 | + |
| 88 | + execute(inputFile.readline.bind(inputFile)); |
| 89 | + |
| 90 | + assertOutputAnswer(__dirname + 'output/09 - hidden files with -a test.txt'); |
| 91 | + }); |
| 92 | + |
| 93 | + test("Directory flag test", function() { |
| 94 | + let inputFile = new File(__dirname + 'input/10 - directory flag test.txt'); |
| 95 | + |
| 96 | + execute(inputFile.readline.bind(inputFile)); |
| 97 | + |
| 98 | + assertOutputAnswer(__dirname + 'output/10 - directory flag test.txt'); |
| 99 | + }); |
| 100 | + |
| 101 | + test("Multiple flags test", function() { |
| 102 | + let inputFile = new File(__dirname + 'input/11 - multiple flags test.txt'); |
| 103 | + |
| 104 | + execute(inputFile.readline.bind(inputFile)); |
| 105 | + |
| 106 | + assertOutputAnswer(__dirname + 'output/11 - multiple flags test.txt'); |
| 107 | + }); |
| 108 | + |
| 109 | + test("All flags test", function() { |
| 110 | + let inputFile = new File(__dirname + 'input/12 - all flags test.txt'); |
| 111 | + |
| 112 | + execute(inputFile.readline.bind(inputFile)); |
| 113 | + |
| 114 | + assertOutputAnswer(__dirname + 'output/12 - all flags test.txt'); |
| 115 | + }); |
| 116 | + |
| 117 | + test("Error handling 1 test", function() { |
| 118 | + let inputFile = new File(__dirname + 'input/13 - error handling 1 test.txt'); |
| 119 | + |
| 120 | + execute(inputFile.readline.bind(inputFile)); |
| 121 | + |
| 122 | + assertOutputAnswer(__dirname + 'output/13 - error handling 1 test.txt'); |
| 123 | + }); |
| 124 | + |
| 125 | + test("Error handling 2 test", function() { |
| 126 | + let inputFile = new File(__dirname + 'input/14 - error handling 2 test.txt'); |
| 127 | + |
| 128 | + execute(inputFile.readline.bind(inputFile)); |
| 129 | + |
| 130 | + assertOutputAnswer(__dirname + 'output/14 - error handling 2 test.txt'); |
| 131 | + }); |
| 132 | + |
| 133 | + test("Error handling 3 test", function() { |
| 134 | + let inputFile = new File(__dirname + 'input/15 - error handling 3 test.txt'); |
| 135 | + |
| 136 | + execute(inputFile.readline.bind(inputFile)); |
| 137 | + |
| 138 | + assertOutputAnswer(__dirname + 'output/15 - error handling 3 test.txt'); |
| 139 | + }); |
| 140 | + |
| 141 | + test("Wrong flag test", function() { |
| 142 | + let inputFile = new File(__dirname + 'input/16 - wrong flag test.txt'); |
| 143 | + |
| 144 | + execute(inputFile.readline.bind(inputFile)); |
| 145 | + |
| 146 | + assertOutputAnswer(__dirname + 'output/16 - wrong flag test.txt'); |
| 147 | + }); |
| 148 | + |
| 149 | + test("Big test 1", function() { |
| 150 | + let inputFile = new File(__dirname + 'input/17 - big test 1.txt'); |
| 151 | + |
| 152 | + execute(inputFile.readline.bind(inputFile)); |
| 153 | + |
| 154 | + assertOutputAnswer(__dirname + 'output/17 - big test 1.txt'); |
| 155 | + }); |
| 156 | + |
| 157 | + test("Not starting in .", function() { |
| 158 | + let inputFile = new File(__dirname + 'input/18 - not starting in.txt'); |
| 159 | + |
| 160 | + execute(inputFile.readline.bind(inputFile)); |
| 161 | + |
| 162 | + assertOutputAnswer(__dirname + 'output/18 - not starting in.txt'); |
| 163 | + }); |
| 164 | +}); |
0 commit comments