trackler 2.2.1.25 → 2.2.1.26

Sign up to get free protection for your applications and to get access to all the features.
Files changed (133) hide show
  1. checksums.yaml +4 -4
  2. data/lib/trackler/version.rb +1 -1
  3. data/tracks/csharp/docs/GENERATORS.md +6 -2
  4. data/tracks/csharp/docs/TESTS.md +2 -20
  5. data/tracks/csharp/exercises/Exercises.sln +557 -554
  6. data/tracks/csharp/exercises/accumulate/Accumulate.csproj +2 -2
  7. data/tracks/csharp/exercises/acronym/Acronym.csproj +2 -2
  8. data/tracks/csharp/exercises/all-your-base/AllYourBase.csproj +2 -2
  9. data/tracks/csharp/exercises/allergies/Allergies.csproj +2 -2
  10. data/tracks/csharp/exercises/alphametics/Alphametics.csproj +2 -2
  11. data/tracks/csharp/exercises/anagram/Anagram.csproj +2 -2
  12. data/tracks/csharp/exercises/atbash-cipher/AtbashCipher.csproj +2 -2
  13. data/tracks/csharp/exercises/bank-account/BankAccount.csproj +2 -2
  14. data/tracks/csharp/exercises/beer-song/BeerSong.csproj +2 -2
  15. data/tracks/csharp/exercises/binary-search-tree/BinarySearchTree.csproj +2 -2
  16. data/tracks/csharp/exercises/binary-search/BinarySearch.csproj +2 -2
  17. data/tracks/csharp/exercises/bob/Bob.csproj +2 -2
  18. data/tracks/csharp/exercises/book-store/BookStore.csproj +2 -2
  19. data/tracks/csharp/exercises/bowling/Bowling.csproj +2 -2
  20. data/tracks/csharp/exercises/bracket-push/BracketPush.csproj +2 -2
  21. data/tracks/csharp/exercises/change/Change.csproj +2 -2
  22. data/tracks/csharp/exercises/circular-buffer/CircularBuffer.csproj +2 -2
  23. data/tracks/csharp/exercises/clock/Clock.csproj +2 -2
  24. data/tracks/csharp/exercises/collatz-conjecture/CollatzConjecture.csproj +1 -1
  25. data/tracks/csharp/exercises/complex-numbers/ComplexNumbers.csproj +2 -2
  26. data/tracks/csharp/exercises/connect/Connect.csproj +2 -2
  27. data/tracks/csharp/exercises/crypto-square/CryptoSquare.csproj +2 -2
  28. data/tracks/csharp/exercises/custom-set/CustomSet.csproj +2 -2
  29. data/tracks/csharp/exercises/diamond/Diamond.csproj +2 -2
  30. data/tracks/csharp/exercises/difference-of-squares/DifferenceOfSquares.csproj +2 -2
  31. data/tracks/csharp/exercises/diffie-hellman/DiffieHellman.csproj +2 -2
  32. data/tracks/csharp/exercises/dominoes/Dominoes.csproj +2 -2
  33. data/tracks/csharp/exercises/dot-dsl/DotDsl.csproj +2 -2
  34. data/tracks/csharp/exercises/error-handling/ErrorHandling.csproj +2 -2
  35. data/tracks/csharp/exercises/etl/Etl.csproj +2 -2
  36. data/tracks/csharp/exercises/flatten-array/FlattenArray.csproj +2 -2
  37. data/tracks/csharp/exercises/food-chain/FoodChain.csproj +2 -2
  38. data/tracks/csharp/exercises/forth/Forth.csproj +2 -2
  39. data/tracks/csharp/exercises/gigasecond/Gigasecond.csproj +2 -2
  40. data/tracks/csharp/exercises/go-counting/GoCounting.csproj +2 -2
  41. data/tracks/csharp/exercises/grade-school/GradeSchool.csproj +2 -2
  42. data/tracks/csharp/exercises/grains/Grains.csproj +2 -2
  43. data/tracks/csharp/exercises/grep/Grep.csproj +2 -2
  44. data/tracks/csharp/exercises/hamming/Hamming.csproj +2 -2
  45. data/tracks/csharp/exercises/hangman/Hangman.csproj +2 -2
  46. data/tracks/csharp/exercises/hello-world/HelloWorld.csproj +2 -2
  47. data/tracks/csharp/exercises/house/House.csproj +2 -2
  48. data/tracks/csharp/exercises/isogram/Isogram.csproj +2 -2
  49. data/tracks/csharp/exercises/kindergarten-garden/KindergartenGarden.csproj +2 -2
  50. data/tracks/csharp/exercises/largest-series-product/LargestSeriesProduct.csproj +2 -2
  51. data/tracks/csharp/exercises/leap/Leap.csproj +2 -2
  52. data/tracks/csharp/exercises/ledger/Ledger.csproj +2 -2
  53. data/tracks/csharp/exercises/linked-list/LinkedList.csproj +2 -2
  54. data/tracks/csharp/exercises/list-ops/ListOps.csproj +2 -2
  55. data/tracks/csharp/exercises/luhn/Luhn.csproj +2 -2
  56. data/tracks/csharp/exercises/markdown/Markdown.csproj +2 -2
  57. data/tracks/csharp/exercises/matrix/Matrix.csproj +2 -2
  58. data/tracks/csharp/exercises/meetup/Meetup.csproj +2 -2
  59. data/tracks/csharp/exercises/minesweeper/Minesweeper.csproj +2 -2
  60. data/tracks/csharp/exercises/nth-prime/NthPrime.csproj +2 -2
  61. data/tracks/csharp/exercises/nucleotide-count/NucleotideCount.csproj +2 -2
  62. data/tracks/csharp/exercises/ocr-numbers/OcrNumbers.csproj +2 -2
  63. data/tracks/csharp/exercises/palindrome-products/PalindromeProducts.csproj +2 -2
  64. data/tracks/csharp/exercises/pangram/Pangram.csproj +2 -2
  65. data/tracks/csharp/exercises/parallel-letter-frequency/ParallelLetterFrequency.csproj +2 -2
  66. data/tracks/csharp/exercises/pascals-triangle/PascalsTriangle.csproj +2 -2
  67. data/tracks/csharp/exercises/perfect-numbers/PerfectNumbers.csproj +2 -2
  68. data/tracks/csharp/exercises/phone-number/PhoneNumber.csproj +2 -2
  69. data/tracks/csharp/exercises/pig-latin/PigLatin.csproj +2 -2
  70. data/tracks/csharp/exercises/poker/Poker.csproj +2 -2
  71. data/tracks/csharp/exercises/pov/Pov.csproj +2 -2
  72. data/tracks/csharp/exercises/prime-factors/PrimeFactors.csproj +2 -2
  73. data/tracks/csharp/exercises/protein-translation/ProteinTranslation.csproj +2 -2
  74. data/tracks/csharp/exercises/proverb/Proverb.csproj +2 -2
  75. data/tracks/csharp/exercises/pythagorean-triplet/PythagoreanTriplet.csproj +2 -2
  76. data/tracks/csharp/exercises/queen-attack/QueenAttack.csproj +2 -2
  77. data/tracks/csharp/exercises/rail-fence-cipher/RailFenceCipher.csproj +2 -2
  78. data/tracks/csharp/exercises/raindrops/Raindrops.csproj +2 -2
  79. data/tracks/csharp/exercises/react/React.csproj +2 -2
  80. data/tracks/csharp/exercises/rectangles/Rectangles.csproj +2 -2
  81. data/tracks/csharp/exercises/rna-transcription/RnaTranscription.csproj +2 -2
  82. data/tracks/csharp/exercises/robot-name/RobotName.csproj +2 -2
  83. data/tracks/csharp/exercises/robot-simulator/RobotSimulator.csproj +2 -2
  84. data/tracks/csharp/exercises/roman-numerals/RomanNumerals.csproj +2 -2
  85. data/tracks/csharp/exercises/rotational-cipher/RotationalCipher.csproj +2 -2
  86. data/tracks/csharp/exercises/run-length-encoding/RunLengthEncoding.csproj +2 -2
  87. data/tracks/csharp/exercises/saddle-points/SaddlePoints.csproj +2 -2
  88. data/tracks/csharp/exercises/say/Say.csproj +2 -2
  89. data/tracks/csharp/exercises/scale-generator/ScaleGenerator.csproj +2 -2
  90. data/tracks/csharp/exercises/scrabble-score/ScrabbleScore.csproj +2 -2
  91. data/tracks/csharp/exercises/secret-handshake/SecretHandshake.csproj +2 -2
  92. data/tracks/csharp/exercises/series/Series.csproj +2 -2
  93. data/tracks/csharp/exercises/sgf-parsing/SgfParsing.csproj +2 -2
  94. data/tracks/csharp/exercises/sieve/Sieve.csproj +2 -2
  95. data/tracks/csharp/exercises/simple-cipher/SimpleCipher.csproj +2 -2
  96. data/tracks/csharp/exercises/simple-linked-list/SimpleLinkedList.csproj +2 -2
  97. data/tracks/csharp/exercises/space-age/SpaceAge.csproj +2 -2
  98. data/tracks/csharp/exercises/strain/Strain.csproj +2 -2
  99. data/tracks/csharp/exercises/sublist/Sublist.csproj +2 -2
  100. data/tracks/csharp/exercises/sum-of-multiples/SumOfMultiples.csproj +2 -2
  101. data/tracks/csharp/exercises/tournament/Tournament.csproj +2 -2
  102. data/tracks/csharp/exercises/transpose/Transpose.csproj +2 -2
  103. data/tracks/csharp/exercises/tree-building/TreeBuilding.csproj +2 -2
  104. data/tracks/csharp/exercises/triangle/Triangle.csproj +2 -2
  105. data/tracks/csharp/exercises/twelve-days/TwelveDays.csproj +2 -2
  106. data/tracks/csharp/exercises/two-bucket/TwoBucket.csproj +2 -2
  107. data/tracks/csharp/exercises/two-fer/TwoFer.csproj +1 -1
  108. data/tracks/csharp/exercises/variable-length-quantity/VariableLengthQuantity.csproj +2 -2
  109. data/tracks/csharp/exercises/word-count/WordCount.csproj +2 -2
  110. data/tracks/csharp/exercises/word-search/WordSearch.csproj +2 -2
  111. data/tracks/csharp/exercises/wordy/Wordy.csproj +2 -2
  112. data/tracks/csharp/exercises/zebra-puzzle/ZebraPuzzle.csproj +2 -2
  113. data/tracks/csharp/exercises/zipper/Zipper.csproj +2 -2
  114. data/tracks/csharp/generators/Generators.csproj +4 -4
  115. data/tracks/ecmascript/exercises/simple-cipher/simple-cipher.spec.js +5 -0
  116. data/tracks/elixir/config.json +11 -0
  117. data/tracks/elixir/exercises/binary-search-tree/README.md +52 -0
  118. data/tracks/elixir/exercises/binary-search-tree/binary_search_tree.exs +27 -0
  119. data/tracks/elixir/exercises/binary-search-tree/binary_search_tree_test.exs +103 -0
  120. data/tracks/elixir/exercises/binary-search-tree/example.exs +29 -0
  121. data/tracks/elixir/exercises/protein-translation/README.md +4 -4
  122. data/tracks/go/exercises/phone-number/.meta/description.md +34 -0
  123. data/tracks/go/exercises/phone-number/.meta/metadata.yml +4 -0
  124. data/tracks/go/exercises/phone-number/README.md +9 -1
  125. data/tracks/javascript/.gitignore +2 -0
  126. data/tracks/javascript/README.md +2 -2
  127. data/tracks/javascript/config.json +14 -1
  128. data/tracks/javascript/exercises/change/README.md +36 -0
  129. data/tracks/javascript/exercises/change/change.spec.js +73 -0
  130. data/tracks/javascript/exercises/change/example.js +204 -0
  131. data/tracks/lua/config/maintainers.json +5 -5
  132. data/tracks/swift/exercises/allergies/Tests/AllergiesTests/AllergiesTests.swift +7 -1
  133. metadata +11 -2
@@ -2,7 +2,7 @@
2
2
 
3
3
  <PropertyGroup>
4
4
  <OutputType>Exe</OutputType>
5
- <TargetFramework>netcoreapp1.0</TargetFramework>
5
+ <TargetFramework>netcoreapp2.0</TargetFramework>
6
6
  </PropertyGroup>
7
7
 
8
8
  <ItemGroup>
@@ -10,7 +10,7 @@
10
10
  </ItemGroup>
11
11
 
12
12
  <ItemGroup>
13
- <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
13
+ <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" />
14
14
  <PackageReference Include="xunit" Version="2.2.0" />
15
15
  <PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
16
16
  </ItemGroup>
@@ -2,7 +2,7 @@
2
2
 
3
3
  <PropertyGroup>
4
4
  <OutputType>Exe</OutputType>
5
- <TargetFramework>netcoreapp1.0</TargetFramework>
5
+ <TargetFramework>netcoreapp2.0</TargetFramework>
6
6
  </PropertyGroup>
7
7
 
8
8
  <ItemGroup>
@@ -10,7 +10,7 @@
10
10
  </ItemGroup>
11
11
 
12
12
  <ItemGroup>
13
- <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
13
+ <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" />
14
14
  <PackageReference Include="xunit" Version="2.2.0" />
15
15
  <PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
16
16
  </ItemGroup>
@@ -2,7 +2,7 @@
2
2
 
3
3
  <PropertyGroup>
4
4
  <OutputType>Exe</OutputType>
5
- <TargetFramework>netcoreapp1.0</TargetFramework>
5
+ <TargetFramework>netcoreapp2.0</TargetFramework>
6
6
  </PropertyGroup>
7
7
 
8
8
  <ItemGroup>
@@ -10,7 +10,7 @@
10
10
  </ItemGroup>
11
11
 
12
12
  <ItemGroup>
13
- <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
13
+ <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" />
14
14
  <PackageReference Include="xunit" Version="2.2.0" />
15
15
  <PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
16
16
  </ItemGroup>
@@ -2,7 +2,7 @@
2
2
 
3
3
  <PropertyGroup>
4
4
  <OutputType>Exe</OutputType>
5
- <TargetFramework>netcoreapp1.0</TargetFramework>
5
+ <TargetFramework>netcoreapp2.0</TargetFramework>
6
6
  </PropertyGroup>
7
7
 
8
8
  <ItemGroup>
@@ -10,7 +10,7 @@
10
10
  </ItemGroup>
11
11
 
12
12
  <ItemGroup>
13
- <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
13
+ <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" />
14
14
  <PackageReference Include="xunit" Version="2.2.0" />
15
15
  <PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
16
16
  </ItemGroup>
@@ -10,7 +10,7 @@
10
10
  </ItemGroup>
11
11
 
12
12
  <ItemGroup>
13
- <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
13
+ <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" />
14
14
  <PackageReference Include="xunit" Version="2.2.0" />
15
15
  <PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
16
16
  </ItemGroup>
@@ -2,7 +2,7 @@
2
2
 
3
3
  <PropertyGroup>
4
4
  <OutputType>Exe</OutputType>
5
- <TargetFramework>netcoreapp1.0</TargetFramework>
5
+ <TargetFramework>netcoreapp2.0</TargetFramework>
6
6
  </PropertyGroup>
7
7
 
8
8
  <ItemGroup>
@@ -10,7 +10,7 @@
10
10
  </ItemGroup>
11
11
 
12
12
  <ItemGroup>
13
- <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
13
+ <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" />
14
14
  <PackageReference Include="xunit" Version="2.2.0" />
15
15
  <PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
16
16
  </ItemGroup>
@@ -2,7 +2,7 @@
2
2
 
3
3
  <PropertyGroup>
4
4
  <OutputType>Exe</OutputType>
5
- <TargetFramework>netcoreapp1.0</TargetFramework>
5
+ <TargetFramework>netcoreapp2.0</TargetFramework>
6
6
  </PropertyGroup>
7
7
 
8
8
  <ItemGroup>
@@ -10,7 +10,7 @@
10
10
  </ItemGroup>
11
11
 
12
12
  <ItemGroup>
13
- <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
13
+ <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" />
14
14
  <PackageReference Include="xunit" Version="2.2.0" />
15
15
  <PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
16
16
  </ItemGroup>
@@ -2,7 +2,7 @@
2
2
 
3
3
  <PropertyGroup>
4
4
  <OutputType>Exe</OutputType>
5
- <TargetFramework>netcoreapp1.0</TargetFramework>
5
+ <TargetFramework>netcoreapp2.0</TargetFramework>
6
6
  </PropertyGroup>
7
7
 
8
8
  <ItemGroup>
@@ -10,7 +10,7 @@
10
10
  </ItemGroup>
11
11
 
12
12
  <ItemGroup>
13
- <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
13
+ <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" />
14
14
  <PackageReference Include="xunit" Version="2.2.0" />
15
15
  <PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
16
16
  </ItemGroup>
@@ -2,7 +2,7 @@
2
2
 
3
3
  <PropertyGroup>
4
4
  <OutputType>Exe</OutputType>
5
- <TargetFramework>netcoreapp1.0</TargetFramework>
5
+ <TargetFramework>netcoreapp2.0</TargetFramework>
6
6
  </PropertyGroup>
7
7
 
8
8
  <ItemGroup>
@@ -10,7 +10,7 @@
10
10
  </ItemGroup>
11
11
 
12
12
  <ItemGroup>
13
- <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
13
+ <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" />
14
14
  <PackageReference Include="xunit" Version="2.2.0" />
15
15
  <PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
16
16
  </ItemGroup>
@@ -2,7 +2,7 @@
2
2
 
3
3
  <PropertyGroup>
4
4
  <OutputType>Exe</OutputType>
5
- <TargetFramework>netcoreapp1.0</TargetFramework>
5
+ <TargetFramework>netcoreapp2.0</TargetFramework>
6
6
  </PropertyGroup>
7
7
 
8
8
  <ItemGroup>
@@ -10,7 +10,7 @@
10
10
  </ItemGroup>
11
11
 
12
12
  <ItemGroup>
13
- <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
13
+ <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" />
14
14
  <PackageReference Include="xunit" Version="2.2.0" />
15
15
  <PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
16
16
  </ItemGroup>
@@ -2,7 +2,7 @@
2
2
 
3
3
  <PropertyGroup>
4
4
  <OutputType>Exe</OutputType>
5
- <TargetFramework>netcoreapp1.0</TargetFramework>
5
+ <TargetFramework>netcoreapp2.0</TargetFramework>
6
6
  </PropertyGroup>
7
7
 
8
8
  <ItemGroup>
@@ -10,7 +10,7 @@
10
10
  </ItemGroup>
11
11
 
12
12
  <ItemGroup>
13
- <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
13
+ <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" />
14
14
  <PackageReference Include="xunit" Version="2.2.0" />
15
15
  <PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
16
16
  </ItemGroup>
@@ -1,16 +1,16 @@
1
1
  <Project Sdk="Microsoft.NET.Sdk">
2
2
  <PropertyGroup>
3
3
  <OutputType>Exe</OutputType>
4
- <TargetFramework>netcoreapp1.1</TargetFramework>
4
+ <TargetFramework>netcoreapp2.0</TargetFramework>
5
5
  </PropertyGroup>
6
6
  <ItemGroup>
7
7
  <PackageReference Include="CommandLineParser" Version="2.1.1-beta" />
8
- <PackageReference Include="DotLiquid" Version="2.0.145" />
8
+ <PackageReference Include="DotLiquid" Version="2.0.180" />
9
9
  <PackageReference Include="Humanizer" Version="2.2.0" />
10
10
  <PackageReference Include="LibGit2Sharp.Portable" Version="0.24.10" />
11
11
  <PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
12
- <PackageReference Include="serilog" Version="2.4.0" />
13
- <PackageReference Include="serilog.sinks.literate" Version="2.1.0" />
12
+ <PackageReference Include="serilog" Version="2.5.0" />
13
+ <PackageReference Include="serilog.sinks.literate" Version="3.0.0" />
14
14
  </ItemGroup>
15
15
  <ItemGroup>
16
16
  <EmbeddedResource Include="Output\Templates\*.liquid" />
@@ -76,4 +76,9 @@ describe('Substitution cipher', () => {
76
76
  xtest('can wrap on decode', () => {
77
77
  expect(cipher.decode('zabcdefghi')).toEqual('zzzzzzzzzz');
78
78
  });
79
+
80
+ xtest('can handle messages longer than the key', function() {
81
+ expect(new Cipher('abc').encode('iamapandabear'))
82
+ .toEqual('iboaqcnecbfcr');
83
+ });
79
84
  });
@@ -568,6 +568,17 @@
568
568
 
569
569
  ]
570
570
  },
571
+ {
572
+ "uuid": "77fe5eb6-a35b-4af4-9512-275f140c25d6",
573
+ "slug": "binary-search-tree",
574
+ "core": false,
575
+ "unlocked_by": null,
576
+ "difficulty": 3,
577
+ "topics": [
578
+ "algorithms",
579
+ "trees"
580
+ ]
581
+ },
571
582
  {
572
583
  "uuid": "47328272-b2f6-42e4-a5a3-a5d276bfbdee",
573
584
  "slug": "prime-factors",
@@ -0,0 +1,52 @@
1
+ Insert and search for numbers in a binary tree.
2
+
3
+ When we need to represent sorted data, an array does not make a good
4
+ data structure.
5
+
6
+ Say we have the array `[1, 3, 4, 5]`, and we add 2 to it so it becomes
7
+ `[1, 3, 4, 5, 2]` now we must sort the entire array again! We can
8
+ improve on this by realizing that we only need to make space for the new
9
+ item `[1, nil, 3, 4, 5]`, and then adding the item in the space we
10
+ added. But this still requires us to shift many elements down by one.
11
+
12
+ Binary Search Trees, however, can operate on sorted data much more
13
+ efficiently.
14
+
15
+ A binary search tree consists of a series of connected nodes. Each node
16
+ contains a piece of data (e.g. the number 3), a variable named `left`,
17
+ and a variable named `right`. The `left` and `right` variables point at
18
+ `nil`, or other nodes. Since these other nodes in turn have other nodes
19
+ beneath them, we say that the left and right variables are pointing at
20
+ subtrees. All data in the left subtree is less than or equal to the
21
+ current node's data, and all data in the right subtree is greater than
22
+ the current node's data.
23
+
24
+ For example, if we had a node containing the data 4, and we added the
25
+ data 2, our tree would look like this:
26
+
27
+ 4
28
+ /
29
+ 2
30
+
31
+ If we then added 6, it would look like this:
32
+
33
+ 4
34
+ / \
35
+ 2 6
36
+
37
+ If we then added 3, it would look like this
38
+
39
+ 4
40
+ / \
41
+ 2 6
42
+ \
43
+ 3
44
+
45
+ And if we then added 1, 5, and 7, it would look like this
46
+
47
+ 4
48
+ / \
49
+ / \
50
+ 2 6
51
+ / \ / \
52
+ 1 3 5 7
@@ -0,0 +1,27 @@
1
+ defmodule BinarySearchTree do
2
+ @type bst_node :: %{data: any, left: bst_node | nil, right: bst_node | nil}
3
+
4
+ @doc """
5
+ Create a new Binary Search Tree with root's value as the given 'data'
6
+ """
7
+ @spec new(any) :: bst_node
8
+ def new(data) do
9
+ # Your implementation here
10
+ end
11
+
12
+ @doc """
13
+ Creates and inserts a node with its value as 'data' into the tree.
14
+ """
15
+ @spec insert(bst_node, any) :: bst_node
16
+ def insert(tree, data) do
17
+ # Your implementation here
18
+ end
19
+
20
+ @doc """
21
+ Traverses the Binary Search Tree in order and returns a list of each node's data.
22
+ """
23
+ @spec in_order(bst_node) :: [any]
24
+ def in_order(tree) do
25
+ # Your implementation here
26
+ end
27
+ end
@@ -0,0 +1,103 @@
1
+ if !System.get_env("EXERCISM_TEST_EXAMPLES") do
2
+ Code.load_file("binary_search_tree.exs", __DIR__)
3
+ end
4
+
5
+ ExUnit.start
6
+ ExUnit.configure exclude: :pending, trace: true
7
+
8
+ defmodule BinarySearchTreeTest do
9
+ use ExUnit.Case
10
+
11
+ test "retains data" do
12
+ assert BinarySearchTree.new(4).data == 4
13
+ end
14
+
15
+ @tag :pending
16
+ test "inserting lower number" do
17
+ root =
18
+ BinarySearchTree.new(4)
19
+ |> BinarySearchTree.insert(2)
20
+
21
+ assert root.data == 4
22
+ assert root.left.data == 2
23
+ end
24
+
25
+ @tag :pending
26
+ test "inserting same number" do
27
+ root =
28
+ BinarySearchTree.new(4)
29
+ |> BinarySearchTree.insert(4)
30
+
31
+ assert root.data == 4
32
+ assert root.left.data == 4
33
+ end
34
+
35
+ @tag :pending
36
+ test "inserting higher number" do
37
+ root =
38
+ BinarySearchTree.new(4)
39
+ |> BinarySearchTree.insert(5)
40
+
41
+ assert root.data == 4
42
+ assert root.right.data == 5
43
+ end
44
+
45
+ @tag :pending
46
+ test "complex tree" do
47
+ root =
48
+ BinarySearchTree.new(4)
49
+ |> BinarySearchTree.insert(2)
50
+ |> BinarySearchTree.insert(6)
51
+ |> BinarySearchTree.insert(1)
52
+ |> BinarySearchTree.insert(3)
53
+ |> BinarySearchTree.insert(7)
54
+ |> BinarySearchTree.insert(5)
55
+
56
+ assert root.data == 4
57
+ assert root.left.data == 2
58
+ assert root.left.left.data == 1
59
+ assert root.left.right.data == 3
60
+ assert root.right.data == 6
61
+ assert root.right.left.data == 5
62
+ assert root.right.right.data == 7
63
+ end
64
+
65
+ @tag :pending
66
+ test "iterating one element" do
67
+ root = BinarySearchTree.new(4)
68
+
69
+ assert [4] == BinarySearchTree.in_order(root)
70
+ end
71
+
72
+ @tag :pending
73
+ test "iterating over smaller element" do
74
+ root =
75
+ BinarySearchTree.new(4)
76
+ |> BinarySearchTree.insert(2)
77
+
78
+ assert [2, 4] == BinarySearchTree.in_order(root)
79
+ end
80
+
81
+ @tag :pending
82
+ test "iterating over larger element" do
83
+ root =
84
+ BinarySearchTree.new(4)
85
+ |> BinarySearchTree.insert(5)
86
+
87
+ assert [4, 5] == BinarySearchTree.in_order(root)
88
+ end
89
+
90
+ @tag :pending
91
+ test "iterating over complex tree" do
92
+ root =
93
+ BinarySearchTree.new(4)
94
+ |> BinarySearchTree.insert(2)
95
+ |> BinarySearchTree.insert(1)
96
+ |> BinarySearchTree.insert(3)
97
+ |> BinarySearchTree.insert(6)
98
+ |> BinarySearchTree.insert(7)
99
+ |> BinarySearchTree.insert(5)
100
+
101
+ assert [1, 2, 3, 4, 5, 6, 7] == BinarySearchTree.in_order(root)
102
+ end
103
+ end
@@ -0,0 +1,29 @@
1
+ defmodule BinarySearchTree do
2
+ def new(data) do
3
+ %{data: data, left: nil, right: nil}
4
+ end
5
+
6
+ def insert(nil, node_value), do: new(node_value)
7
+
8
+ def insert(%{data: data, left: left, right: right}, node_value) do
9
+ if node_value <= data do
10
+ %{data: data, left: insert(left, node_value), right: right}
11
+ else
12
+ %{data: data, left: left, right: insert(right, node_value)}
13
+ end
14
+ end
15
+
16
+ def in_order(tree) do
17
+ in_order(tree, []) |> Enum.reverse
18
+ end
19
+
20
+ def in_order(nil, accum) do
21
+ accum
22
+ end
23
+
24
+ def in_order(tree, accum) do
25
+ left_side = in_order(tree.left, accum)
26
+ middle = [tree.data | left_side]
27
+ in_order(tree.right, middle)
28
+ end
29
+ end