trackler 2.2.1.100 → 2.2.1.101
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/trackler/version.rb +1 -1
- data/problem-specifications/exercises/kindergarten-garden/canonical-data.json +37 -19
- data/problem-specifications/exercises/ocr-numbers/canonical-data.json +144 -110
- data/problem-specifications/exercises/palindrome-products/canonical-data.json +49 -25
- data/problem-specifications/exercises/poker/canonical-data.json +171 -115
- data/problem-specifications/exercises/prime-factors/canonical-data.json +22 -8
- data/problem-specifications/exercises/protein-translation/canonical-data.json +70 -24
- data/problem-specifications/exercises/proverb/canonical-data.json +24 -12
- data/problem-specifications/exercises/queen-attack/canonical-data.json +115 -91
- data/problem-specifications/exercises/rail-fence-cipher/canonical-data.json +25 -13
- data/problem-specifications/exercises/raindrops/canonical-data.json +55 -19
- data/problem-specifications/exercises/rational-numbers/canonical-data.json +374 -0
- data/problem-specifications/exercises/rational-numbers/description.md +27 -0
- data/problem-specifications/exercises/rational-numbers/metadata.yml +4 -0
- data/problem-specifications/exercises/rectangles/canonical-data.json +93 -67
- data/problem-specifications/exercises/reverse-string/canonical-data.json +16 -6
- data/problem-specifications/exercises/rna-transcription/metadata.yml +3 -3
- data/problem-specifications/exercises/roman-numerals/canonical-data.json +10 -2
- data/tracks/bash/config.json +11 -11
- data/tracks/c/exercises/roman-numerals/test/test_roman_numerals.c +7 -0
- data/tracks/clojure/exercises/armstrong-numbers/README.md +1 -1
- data/tracks/delphi/config.json +11 -0
- data/tracks/delphi/exercises/clock/uClockExample.pas +6 -1
- data/tracks/delphi/exercises/clock/uClockTest.pas +22 -19
- data/tracks/delphi/exercises/isbn-verifier/README.md +1 -1
- data/tracks/delphi/exercises/reverse-string/README.md +1 -1
- data/tracks/delphi/exercises/rna-transcription/README.md +1 -1
- data/tracks/delphi/exercises/roman-numerals/uRomanNumeralsTest.pas +14 -0
- data/tracks/delphi/exercises/space-age/README.md +45 -0
- data/tracks/delphi/exercises/space-age/SpaceAge.dpr +60 -0
- data/tracks/delphi/exercises/space-age/uSpaceAgeExample.pas +120 -0
- data/tracks/delphi/exercises/space-age/uSpaceAgeTests.pas +135 -0
- data/tracks/delphi/exercises/two-fer/README.md +1 -1
- data/tracks/elixir/exercises/nth-prime/nth_prime.exs +0 -1
- data/tracks/fsharp/exercises/pov/PovTest.fs +66 -53
- data/tracks/fsharp/exercises/space-age/Example.fs +11 -11
- data/tracks/fsharp/exercises/space-age/SpaceAge.fs +1 -1
- data/tracks/fsharp/exercises/space-age/SpaceAgeTest.fs +21 -34
- data/tracks/fsharp/exercises/triangle/Example.fs +11 -16
- data/tracks/fsharp/exercises/triangle/Triangle.fs +4 -5
- data/tracks/fsharp/exercises/triangle/TriangleTest.fs +44 -31
- data/tracks/fsharp/generators/Generators.fs +121 -0
- data/tracks/go/config.json +12 -0
- data/tracks/go/exercises/clock/.meta/gen.go +37 -13
- data/tracks/go/exercises/clock/cases_test.go +10 -10
- data/tracks/go/exercises/clock/clock_test.go +16 -2
- data/tracks/go/exercises/clock/example.go +4 -0
- data/tracks/go/exercises/clock/example_clock_test.go +3 -3
- data/tracks/go/exercises/parallel-letter-frequency/.meta/hints.md +33 -0
- data/tracks/go/exercises/parallel-letter-frequency/README.md +35 -0
- data/tracks/go/exercises/raindrops/.meta/hints.md +7 -4
- data/tracks/go/exercises/raindrops/README.md +12 -0
- data/tracks/go/exercises/roman-numerals/.meta/gen.go +4 -2
- data/tracks/go/exercises/roman-numerals/cases_test.go +3 -2
- data/tracks/go/exercises/space-age/.meta/hints.md +10 -0
- data/tracks/go/exercises/space-age/README.md +14 -1
- data/tracks/go/exercises/twelve-days/README.md +2 -5
- data/tracks/go/exercises/two-bucket/.meta/gen.go +62 -0
- data/tracks/go/exercises/two-bucket/.meta/hints.md +16 -0
- data/tracks/go/exercises/two-bucket/README.md +72 -0
- data/tracks/go/exercises/two-bucket/cases_test.go +44 -0
- data/tracks/go/exercises/two-bucket/example.go +198 -0
- data/tracks/go/exercises/two-bucket/two_bucket_test.go +61 -0
- data/tracks/idris/.travis.yml +3 -2
- data/tracks/idris/bin/fetch-idris-testing.sh +11 -0
- data/tracks/idris/bin/solve_exercises.sh +2 -2
- data/tracks/idris/config.json +11 -0
- data/tracks/idris/config/exercise_readme.go.tmpl +0 -3
- data/tracks/idris/docs/INSTALLATION.md +22 -0
- data/tracks/idris/docs/TESTS.md +12 -4
- data/tracks/idris/exercises/accumulate/src/Accumulate.idr +5 -0
- data/tracks/idris/exercises/hamming/Hamming.ipkg +2 -0
- data/tracks/idris/exercises/hamming/src/{example.idr → Example.idr} +5 -1
- data/tracks/idris/exercises/hamming/src/Hamming.idr +13 -5
- data/tracks/idris/exercises/hamming/src/Test/Hamming.idr +31 -58
- data/tracks/idris/exercises/hello-world/HelloWorld.ipkg +2 -0
- data/tracks/idris/exercises/hello-world/src/Example.idr +9 -0
- data/tracks/idris/exercises/hello-world/src/HelloWorld.idr +6 -1
- data/tracks/idris/exercises/hello-world/src/Test/HelloWorld.idr +18 -18
- data/tracks/idris/exercises/leap/Leap.ipkg +2 -0
- data/tracks/idris/exercises/leap/src/{example.idr → Example.idr} +4 -0
- data/tracks/idris/exercises/leap/src/Leap.idr +5 -1
- data/tracks/idris/exercises/leap/src/Test/Leap.idr +21 -30
- data/tracks/idris/exercises/rna-transcription/Makefile +23 -0
- data/tracks/idris/exercises/rna-transcription/README.md +27 -0
- data/tracks/idris/exercises/rna-transcription/RnaTranscription.ipkg +5 -0
- data/tracks/idris/exercises/rna-transcription/src/RnaTranscription.idr +17 -0
- data/tracks/idris/exercises/rna-transcription/src/Test/RnaTranscription.idr +27 -0
- data/tracks/idris/exercises/rna-transcription/src/example.idr +35 -0
- data/tracks/java/exercises/etl/.meta/version +1 -0
- data/tracks/java/exercises/gigasecond/.meta/version +1 -0
- data/tracks/java/exercises/isbn-verifier/README.md +1 -1
- data/tracks/java/exercises/nucleotide-count/.meta/src/reference/java/NucleotideCounter.java +7 -1
- data/tracks/java/exercises/nucleotide-count/.meta/version +1 -0
- data/tracks/java/exercises/nucleotide-count/src/test/java/NucleotideCounterTest.java +19 -54
- data/tracks/java/exercises/proverb/.meta/version +1 -0
- data/tracks/java/exercises/reverse-string/README.md +1 -1
- data/tracks/java/exercises/rna-transcription/README.md +1 -1
- data/tracks/java/exercises/sum-of-multiples/.meta/version +1 -0
- data/tracks/java/exercises/sum-of-multiples/src/test/java/SumOfMultiplesTest.java +13 -1
- data/tracks/kotlin/config/exercise_readme.go.tmpl +0 -3
- data/tracks/kotlin/docs/TESTS.md +1 -1
- data/tracks/objective-c/config.json +11 -0
- data/tracks/objective-c/exercises/collatz-conjecture/CollatzConjectureExample.h +7 -0
- data/tracks/objective-c/exercises/collatz-conjecture/CollatzConjectureExample.m +26 -0
- data/tracks/objective-c/exercises/collatz-conjecture/CollatzConjectureTest.m +39 -0
- data/tracks/objective-c/xcodeProject/ObjectiveC.xcodeproj/project.pbxproj +31 -1
- data/tracks/objective-c/xcodeProject/ObjectiveC.xcodeproj/xcshareddata/xcschemes/OCLint.xcscheme +3 -1
- data/tracks/objective-c/xcodeProject/ObjectiveC.xcodeproj/xcshareddata/xcschemes/xobjectivecTest.xcscheme +3 -1
- data/tracks/ocaml/exercises/forth/example.ml +9 -9
- data/tracks/ocaml/tools/test-generator/Makefile +3 -9
- data/tracks/ocaml/tools/test-generator/src/test_gen.ml +18 -16
- data/tracks/perl6/exercises/acronym/.meta/exercise-data.yaml +1 -1
- data/tracks/perl6/exercises/acronym/acronym.t +4 -14
- data/tracks/perl6/exercises/all-your-base/all-your-base.t +0 -2
- data/tracks/perl6/exercises/allergies/allergies.t +0 -2
- data/tracks/perl6/exercises/anagram/.meta/exercise-data.yaml +1 -1
- data/tracks/perl6/exercises/anagram/anagram.t +2 -40
- data/tracks/perl6/exercises/atbash-cipher/atbash-cipher.t +0 -1
- data/tracks/perl6/exercises/bob/bob.t +0 -2
- data/tracks/perl6/exercises/clock/.meta/exercise-data.yaml +15 -11
- data/tracks/perl6/exercises/clock/.meta/solutions/Clock.pm6 +5 -1
- data/tracks/perl6/exercises/clock/Clock.pm6 +1 -1
- data/tracks/perl6/exercises/clock/clock.t +314 -217
- data/tracks/perl6/exercises/etl/etl.t +0 -2
- data/tracks/perl6/exercises/flatten-array/flatten-array.t +0 -2
- data/tracks/perl6/exercises/grains/grains.t +0 -2
- data/tracks/perl6/exercises/hamming/.meta/exercise-data.yaml +2 -2
- data/tracks/perl6/exercises/hamming/hamming.t +63 -35
- data/tracks/perl6/exercises/hello-world/hello-world.t +2 -3
- data/tracks/perl6/exercises/leap/.meta/exercise-data.yaml +1 -1
- data/tracks/perl6/exercises/leap/leap.t +14 -8
- data/tracks/perl6/exercises/luhn/luhn.t +0 -2
- data/tracks/perl6/exercises/nucleotide-count/.meta/exercise-data.yaml +2 -2
- data/tracks/perl6/exercises/nucleotide-count/nucleotide-count.t +18 -10
- data/tracks/perl6/exercises/pangram/.meta/exercise-data.yaml +1 -1
- data/tracks/perl6/exercises/pangram/pangram.t +32 -14
- data/tracks/perl6/exercises/phone-number/.meta/exercise-data.yaml +4 -4
- data/tracks/perl6/exercises/phone-number/.meta/solutions/Phone.pm6 +1 -1
- data/tracks/perl6/exercises/phone-number/Phone.pm6 +1 -1
- data/tracks/perl6/exercises/phone-number/phone-number.t +59 -21
- data/tracks/perl6/exercises/raindrops/raindrops.t +0 -2
- data/tracks/perl6/exercises/rna-transcription/.meta/exercise-data.yaml +1 -1
- data/tracks/perl6/exercises/rna-transcription/README.md +1 -1
- data/tracks/perl6/exercises/rna-transcription/rna-transcription.t +17 -9
- data/tracks/perl6/exercises/roman-numerals/.meta/exercise-data.yaml +3 -3
- data/tracks/perl6/exercises/roman-numerals/.meta/solutions/RomanNumerals.pm6 +1 -1
- data/tracks/perl6/exercises/roman-numerals/RomanNumerals.pm6 +1 -1
- data/tracks/perl6/exercises/roman-numerals/roman-numerals.t +66 -24
- data/tracks/perl6/exercises/scrabble-score/.meta/exercise-data.yaml +1 -1
- data/tracks/perl6/exercises/scrabble-score/scrabble-score.t +35 -15
- data/tracks/perl6/exercises/space-age/.meta/exercise-data.yaml +1 -1
- data/tracks/perl6/exercises/space-age/space-age.t +34 -20
- data/tracks/perl6/exercises/two-fer/.meta/exercise-data.yaml +2 -2
- data/tracks/perl6/exercises/two-fer/two-fer.t +15 -11
- data/tracks/perl6/exercises/word-count/.meta/exercise-data.yaml +1 -1
- data/tracks/perl6/exercises/word-count/word-count.t +46 -26
- data/tracks/perl6/exercises/wordy/.meta/exercise-data.yaml +2 -2
- data/tracks/perl6/exercises/wordy/wordy.t +51 -21
- data/tracks/perl6/lib/Exercism/Generator.pm6 +1 -1
- data/tracks/perl6/t/generated-tests.t +1 -1
- data/tracks/perl6/templates/test.mustache +0 -1
- data/tracks/python/config.json +12 -0
- data/tracks/python/exercises/forth/example.py +1 -1
- data/tracks/python/exercises/forth/forth_test.py +43 -38
- data/tracks/python/exercises/spiral-matrix/README.md +42 -0
- data/tracks/python/exercises/spiral-matrix/example.py +11 -0
- data/tracks/python/exercises/spiral-matrix/spiral_matrix.py +2 -0
- data/tracks/python/exercises/spiral-matrix/spiral_matrix_test.py +40 -0
- data/tracks/racket/config/exercise_readme.go.tmpl +24 -4
- data/tracks/racket/exercises/accumulate/README.md +3 -6
- data/tracks/racket/exercises/acronym/README.md +3 -4
- data/tracks/racket/exercises/allergies/README.md +3 -4
- data/tracks/racket/exercises/anagram/README.md +3 -3
- data/tracks/racket/exercises/bob/README.md +5 -3
- data/tracks/racket/exercises/collatz-conjecture/README.md +3 -3
- data/tracks/racket/exercises/difference-of-squares/README.md +3 -3
- data/tracks/racket/exercises/etl/README.md +6 -4
- data/tracks/racket/exercises/gigasecond/README.md +3 -3
- data/tracks/racket/exercises/grains/README.md +3 -4
- data/tracks/racket/exercises/grep/README.md +15 -15
- data/tracks/racket/exercises/hamming/README.md +3 -3
- data/tracks/racket/exercises/hello-world/README.md +1 -1
- data/tracks/racket/exercises/leap/README.md +4 -4
- data/tracks/racket/exercises/list-ops/README.md +3 -4
- data/tracks/racket/exercises/meetup/README.md +19 -15
- data/tracks/racket/exercises/nucleotide-count/README.md +11 -25
- data/tracks/racket/exercises/perfect-numbers/README.md +5 -5
- data/tracks/racket/exercises/phone-number/README.md +7 -6
- data/tracks/racket/exercises/raindrops/README.md +3 -3
- data/tracks/racket/exercises/rna-transcription/README.md +4 -4
- data/tracks/racket/exercises/roman-numerals/README.md +4 -4
- data/tracks/racket/exercises/say/README.md +3 -3
- data/tracks/racket/exercises/scrabble-score/README.md +6 -4
- data/tracks/racket/exercises/word-count/README.md +4 -5
- data/tracks/scheme/config/exercise_readme.go.tmpl +0 -3
- data/tracks/scheme/docs/INSTALLATION.md +23 -14
- metadata +40 -9
- data/tracks/idris/docs/EXERCISE_README_INSERT.md +0 -0
- data/tracks/idris/exercises/hello-world/src/example.idr +0 -5
- data/tracks/kotlin/config/exercise-readme-insert.md +0 -1
- data/tracks/racket/docs/EXERCISE_README_INSERT.md +0 -23
- data/tracks/scheme/docs/EXERCISE_README_INSERT.md +0 -0
@@ -34,7 +34,7 @@ For example, if you're submitting `ubob.pas` for the Bob exercise, the submit co
|
|
34
34
|
|
35
35
|
## Source
|
36
36
|
|
37
|
-
This is an exercise to introduce users to basic programming constructs, just after
|
37
|
+
This is an exercise to introduce users to basic programming constructs, just after Hello World. [https://en.wikipedia.org/wiki/Two-fer](https://en.wikipedia.org/wiki/Two-fer)
|
38
38
|
|
39
39
|
## Submitting Incomplete Solutions
|
40
40
|
It's possible to submit an incomplete solution so you can see how others have completed the exercise.
|
@@ -1,80 +1,93 @@
|
|
1
|
-
// This file was
|
1
|
+
// This file was auto-generated based on version 1.1.1 of the canonical data.
|
2
2
|
|
3
3
|
module PovTest
|
4
4
|
|
5
|
-
open Xunit
|
6
5
|
open FsUnit.Xunit
|
6
|
+
open Xunit
|
7
7
|
|
8
8
|
open Pov
|
9
9
|
|
10
|
-
let
|
11
|
-
let
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
let
|
17
|
-
let cousins = mkGraph "grandparent" [
|
18
|
-
mkGraph "parent" [
|
19
|
-
mkGraph x [leaf "kid-a"; leaf "kid-b"];
|
20
|
-
(leaf "sibling-0");
|
21
|
-
(leaf "sibling-1")];
|
22
|
-
mkGraph "uncle" [
|
23
|
-
(leaf "cousin-0");
|
24
|
-
(leaf "cousin-1")]]
|
25
|
-
|
26
|
-
let singleton' = singleton
|
27
|
-
let flat' = mkGraph x [mkGraph "root" (List.map leaf ["a"; "b"; "c"])]
|
28
|
-
let nested' = mkGraph x [mkGraph "level-3" [mkGraph "level-2" [mkGraph "level-1" [mkGraph "level-0" []]]]]
|
29
|
-
let kids' = mkGraph x [mkGraph "kid-0" []; mkGraph "kid-1" []; mkGraph "root" []]
|
30
|
-
let cousins' = mkGraph x [
|
31
|
-
leaf "kid-a";
|
32
|
-
leaf "kid-b";
|
33
|
-
mkGraph "parent" [
|
34
|
-
mkGraph "sibling-0" [];
|
35
|
-
mkGraph "sibling-1" [];
|
36
|
-
mkGraph "grandparent" [
|
37
|
-
mkGraph "uncle" [
|
38
|
-
mkGraph "cousin-0" [];
|
39
|
-
mkGraph "cousin-1" []]]]]
|
10
|
+
let rec graphToList graph =
|
11
|
+
let right =
|
12
|
+
graph.children
|
13
|
+
|> List.sortBy (fun x -> x.value)
|
14
|
+
|> List.collect graphToList
|
15
|
+
[graph.value] @ right
|
16
|
+
let mapToList graph = match graph with | Some x -> graphToList x | None -> []
|
40
17
|
|
41
18
|
[<Fact>]
|
42
|
-
let ``
|
43
|
-
|
19
|
+
let ``Results in the same tree if the input tree is a singleton`` () =
|
20
|
+
let tree = mkGraph "x" []
|
21
|
+
let expected = mkGraph "x" []
|
22
|
+
fromPOV "x" tree |> mapToList |> should equal <| graphToList expected
|
23
|
+
|
24
|
+
[<Fact(Skip = "Remove to run test")>]
|
25
|
+
let ``Can reroot a tree with a parent and one sibling`` () =
|
26
|
+
let tree = mkGraph "parent" [mkGraph "x" []; mkGraph "sibling" []]
|
27
|
+
let expected = mkGraph "x" [mkGraph "parent" [mkGraph "sibling" []]]
|
28
|
+
fromPOV "x" tree |> mapToList |> should equal <| graphToList expected
|
29
|
+
|
30
|
+
[<Fact(Skip = "Remove to run test")>]
|
31
|
+
let ``Can reroot a tree with a parent and many siblings`` () =
|
32
|
+
let tree = mkGraph "parent" [mkGraph "a" []; mkGraph "x" []; mkGraph "b" []; mkGraph "c" []]
|
33
|
+
let expected = mkGraph "x" [mkGraph "parent" [mkGraph "a" []; mkGraph "b" []; mkGraph "c" []]]
|
34
|
+
fromPOV "x" tree |> mapToList |> should equal <| graphToList expected
|
44
35
|
|
45
36
|
[<Fact(Skip = "Remove to run test")>]
|
46
|
-
let ``
|
47
|
-
|
37
|
+
let ``Can reroot a tree with new root deeply nested in tree`` () =
|
38
|
+
let tree = mkGraph "level-0" [mkGraph "level-1" [mkGraph "level-2" [mkGraph "level-3" [mkGraph "x" []]]]]
|
39
|
+
let expected = mkGraph "x" [mkGraph "level-3" [mkGraph "level-2" [mkGraph "level-1" [mkGraph "level-0" []]]]]
|
40
|
+
fromPOV "x" tree |> mapToList |> should equal <| graphToList expected
|
48
41
|
|
49
42
|
[<Fact(Skip = "Remove to run test")>]
|
50
|
-
let ``
|
51
|
-
|
43
|
+
let ``Moves children of the new root to same level as former parent`` () =
|
44
|
+
let tree = mkGraph "parent" [mkGraph "x" [mkGraph "kid-0" []; mkGraph "kid-1" []]]
|
45
|
+
let expected = mkGraph "x" [mkGraph "kid-0" []; mkGraph "kid-1" []; mkGraph "parent" []]
|
46
|
+
fromPOV "x" tree |> mapToList |> should equal <| graphToList expected
|
52
47
|
|
53
48
|
[<Fact(Skip = "Remove to run test")>]
|
54
|
-
let ``
|
55
|
-
|
49
|
+
let ``Can reroot a complex tree with cousins`` () =
|
50
|
+
let tree = mkGraph "grandparent" [mkGraph "parent" [mkGraph "x" [mkGraph "kid-0" []; mkGraph "kid-1" []]; mkGraph "sibling-0" []; mkGraph "sibling-1" []]; mkGraph "uncle" [mkGraph "cousin-0" []; mkGraph "cousin-1" []]]
|
51
|
+
let expected = mkGraph "x" [mkGraph "kid-1" []; mkGraph "kid-0" []; mkGraph "parent" [mkGraph "sibling-0" []; mkGraph "sibling-1" []; mkGraph "grandparent" [mkGraph "uncle" [mkGraph "cousin-0" []; mkGraph "cousin-1" []]]]]
|
52
|
+
fromPOV "x" tree |> mapToList |> should equal <| graphToList expected
|
56
53
|
|
57
54
|
[<Fact(Skip = "Remove to run test")>]
|
58
|
-
let ``
|
59
|
-
|
55
|
+
let ``Errors if target does not exist in a singleton tree`` () =
|
56
|
+
let tree = mkGraph "x" []
|
57
|
+
fromPOV "nonexistent" tree |> should equal None
|
60
58
|
|
61
59
|
[<Fact(Skip = "Remove to run test")>]
|
62
|
-
let ``
|
63
|
-
|
60
|
+
let ``Errors if target does not exist in a large tree`` () =
|
61
|
+
let tree = mkGraph "parent" [mkGraph "x" [mkGraph "kid-0" []; mkGraph "kid-1" []]; mkGraph "sibling-0" []; mkGraph "sibling-1" []]
|
62
|
+
fromPOV "nonexistent" tree |> should equal None
|
64
63
|
|
65
64
|
[<Fact(Skip = "Remove to run test")>]
|
66
|
-
let ``
|
67
|
-
let
|
68
|
-
|
65
|
+
let ``Can find path to parent`` () =
|
66
|
+
let tree = mkGraph "parent" [mkGraph "x" []; mkGraph "sibling" []]
|
67
|
+
tracePathBetween "x" "parent" tree |> should equal <| Some ["x"; "parent"]
|
69
68
|
|
70
69
|
[<Fact(Skip = "Remove to run test")>]
|
71
|
-
let ``
|
72
|
-
|
70
|
+
let ``Can find path to sibling`` () =
|
71
|
+
let tree = mkGraph "parent" [mkGraph "a" []; mkGraph "x" []; mkGraph "b" []; mkGraph "c" []]
|
72
|
+
tracePathBetween "x" "b" tree |> should equal <| Some ["x"; "parent"; "b"]
|
73
73
|
|
74
74
|
[<Fact(Skip = "Remove to run test")>]
|
75
|
-
let ``Can
|
76
|
-
|
75
|
+
let ``Can find path to cousin`` () =
|
76
|
+
let tree = mkGraph "grandparent" [mkGraph "parent" [mkGraph "x" [mkGraph "kid-0" []; mkGraph "kid-1" []]; mkGraph "sibling-0" []; mkGraph "sibling-1" []]; mkGraph "uncle" [mkGraph "cousin-0" []; mkGraph "cousin-1" []]]
|
77
|
+
tracePathBetween "x" "cousin-1" tree |> should equal <| Some ["x"; "parent"; "grandparent"; "uncle"; "cousin-1"]
|
77
78
|
|
78
79
|
[<Fact(Skip = "Remove to run test")>]
|
79
|
-
let ``Can
|
80
|
-
|
80
|
+
let ``Can find path from nodes other than x`` () =
|
81
|
+
let tree = mkGraph "parent" [mkGraph "a" []; mkGraph "x" []; mkGraph "b" []; mkGraph "c" []]
|
82
|
+
tracePathBetween "a" "c" tree |> should equal <| Some ["a"; "parent"; "c"]
|
83
|
+
|
84
|
+
[<Fact(Skip = "Remove to run test")>]
|
85
|
+
let ``Errors if destination does not exist`` () =
|
86
|
+
let tree = mkGraph "parent" [mkGraph "x" [mkGraph "kid-0" []; mkGraph "kid-1" []]; mkGraph "sibling-0" []; mkGraph "sibling-1" []]
|
87
|
+
tracePathBetween "x" "nonexistent" tree |> should equal None
|
88
|
+
|
89
|
+
[<Fact(Skip = "Remove to run test")>]
|
90
|
+
let ``Errors if source does not exist`` () =
|
91
|
+
let tree = mkGraph "parent" [mkGraph "x" [mkGraph "kid-0" []; mkGraph "kid-1" []]; mkGraph "sibling-0" []; mkGraph "sibling-1" []]
|
92
|
+
tracePathBetween "nonexistent" "x" tree |> should equal None
|
93
|
+
|
@@ -12,20 +12,20 @@ type Planet =
|
|
12
12
|
| Neptune
|
13
13
|
| Uranus
|
14
14
|
|
15
|
-
let secondsOnEarth =
|
15
|
+
let secondsOnEarth = 31557600.0
|
16
16
|
|
17
17
|
let planetPeriods =
|
18
|
-
[Mercury, 0.
|
19
|
-
Venus, 0.
|
20
|
-
Earth, 1.
|
21
|
-
Mars, 1.
|
22
|
-
Jupiter, 11.
|
23
|
-
Saturn, 29.
|
24
|
-
Uranus, 84.
|
25
|
-
Neptune, 164.
|
18
|
+
[Mercury, 0.2408467;
|
19
|
+
Venus, 0.61519726;
|
20
|
+
Earth, 1.0;
|
21
|
+
Mars, 1.8808158;
|
22
|
+
Jupiter, 11.862615;
|
23
|
+
Saturn, 29.447498;
|
24
|
+
Uranus, 84.016846;
|
25
|
+
Neptune, 164.79132]
|
26
26
|
|> Map.ofList
|
27
27
|
|
28
|
-
let
|
29
|
-
let yearsUsingPeriod (period:
|
28
|
+
let age planet (seconds: int64) =
|
29
|
+
let yearsUsingPeriod (period: float) = Math.Round((float seconds / period) / secondsOnEarth, 2)
|
30
30
|
|
31
31
|
yearsUsingPeriod planetPeriods.[planet]
|
@@ -1,54 +1,41 @@
|
|
1
|
-
// This file was
|
1
|
+
// This file was auto-generated based on version 1.1.0 of the canonical data.
|
2
2
|
|
3
3
|
module SpaceAgeTest
|
4
4
|
|
5
|
-
open Xunit
|
6
5
|
open FsUnit.Xunit
|
6
|
+
open Xunit
|
7
|
+
|
7
8
|
open SpaceAge
|
8
|
-
|
9
|
+
|
9
10
|
[<Fact>]
|
10
|
-
let ``Age on
|
11
|
-
|
12
|
-
spaceAge Planet.Earth seconds |> should equal 31.69m
|
11
|
+
let ``Age on Earth`` () =
|
12
|
+
age Earth 1000000000L |> should equal 31.69
|
13
13
|
|
14
14
|
[<Fact(Skip = "Remove to run test")>]
|
15
|
-
let ``Age on
|
16
|
-
|
17
|
-
spaceAge Planet.Earth seconds |> should equal 67.65m
|
18
|
-
spaceAge Planet.Mercury seconds |> should equal 280.88m
|
15
|
+
let ``Age on Mercury`` () =
|
16
|
+
age Mercury 2134835688L |> should equal 280.88
|
19
17
|
|
20
18
|
[<Fact(Skip = "Remove to run test")>]
|
21
|
-
let ``Age on
|
22
|
-
|
23
|
-
spaceAge Planet.Earth seconds |> should equal 6.02m
|
24
|
-
spaceAge Planet.Venus seconds |> should equal 9.78m
|
19
|
+
let ``Age on Venus`` () =
|
20
|
+
age Venus 189839836L |> should equal 9.78
|
25
21
|
|
26
22
|
[<Fact(Skip = "Remove to run test")>]
|
27
|
-
let ``Age on
|
28
|
-
|
29
|
-
spaceAge Planet.Earth seconds |> should equal 73.83m
|
30
|
-
spaceAge Planet.Mars seconds |> should equal 39.25m
|
23
|
+
let ``Age on Mars`` () =
|
24
|
+
age Mars 2329871239L |> should equal 39.25
|
31
25
|
|
32
26
|
[<Fact(Skip = "Remove to run test")>]
|
33
|
-
let ``Age on
|
34
|
-
|
35
|
-
spaceAge Planet.Earth seconds |> should equal 28.58m
|
36
|
-
spaceAge Planet.Jupiter seconds |> should equal 2.41m
|
27
|
+
let ``Age on Jupiter`` () =
|
28
|
+
age Jupiter 901876382L |> should equal 2.41
|
37
29
|
|
38
30
|
[<Fact(Skip = "Remove to run test")>]
|
39
|
-
let ``Age on
|
40
|
-
|
41
|
-
spaceAge Planet.Earth seconds |> should equal 95.06m
|
42
|
-
spaceAge Planet.Saturn seconds |> should equal 3.23m
|
31
|
+
let ``Age on Saturn`` () =
|
32
|
+
age Saturn 3000000000L |> should equal 3.23
|
43
33
|
|
44
34
|
[<Fact(Skip = "Remove to run test")>]
|
45
|
-
let ``Age on
|
46
|
-
|
47
|
-
spaceAge Planet.Earth seconds |> should equal 101.72m
|
48
|
-
spaceAge Planet.Uranus seconds |> should equal 1.21m
|
35
|
+
let ``Age on Uranus`` () =
|
36
|
+
age Uranus 3210123456L |> should equal 1.21
|
49
37
|
|
50
38
|
[<Fact(Skip = "Remove to run test")>]
|
51
|
-
let ``Age on
|
52
|
-
|
53
|
-
|
54
|
-
spaceAge Planet.Neptune seconds |> should equal 1.58m
|
39
|
+
let ``Age on Neptune`` () =
|
40
|
+
age Neptune 8210123456L |> should equal 1.58
|
41
|
+
|
@@ -1,22 +1,17 @@
|
|
1
1
|
module Triangle
|
2
2
|
|
3
|
-
|
3
|
+
let private isValid triangle =
|
4
|
+
let nonZero = List.sum triangle <> 0.0
|
5
|
+
let equality =
|
6
|
+
let [x; y; z] = triangle
|
7
|
+
x + y >= z && x + z >= y && y + z >= x
|
8
|
+
|
9
|
+
equality && nonZero
|
4
10
|
|
5
|
-
|
6
|
-
| Equilateral
|
7
|
-
| Isosceles
|
8
|
-
| Scalene
|
11
|
+
let private distinctSides triangle = triangle |> List.distinct |> List.length
|
9
12
|
|
10
|
-
let
|
11
|
-
let hasZeroSides = x = 0m && y = 0m && z = 0m
|
12
|
-
let hasNegativeSide = x < 0m || y < 0m || z < 0m
|
13
|
-
let violatesTriangleEquality = x + y <= z || x + z <= y || y + z <= x
|
13
|
+
let equilateral triangle = isValid triangle && distinctSides triangle = 1
|
14
14
|
|
15
|
-
|
16
|
-
let isEquilateral = x = y && y = z
|
17
|
-
let isIsosceles = x = y || y = z || x = z
|
15
|
+
let isosceles triangle = isValid triangle && distinctSides triangle <= 2
|
18
16
|
|
19
|
-
|
20
|
-
elif isEquilateral then TriangleKind.Equilateral
|
21
|
-
elif isIsosceles then TriangleKind.Isosceles
|
22
|
-
else TriangleKind.Scalene
|
17
|
+
let scalene triangle = isValid triangle && distinctSides triangle = 3
|
@@ -1,8 +1,7 @@
|
|
1
1
|
module Triangle
|
2
2
|
|
3
|
-
|
4
|
-
| Equilateral
|
5
|
-
| Isosceles
|
6
|
-
| Scalene
|
3
|
+
let equilateral triangle = failwith "You need to implement this function."
|
7
4
|
|
8
|
-
let
|
5
|
+
let isosceles triangle = failwith "You need to implement this function."
|
6
|
+
|
7
|
+
let scalene triangle = failwith "You need to implement this function."
|
@@ -1,64 +1,77 @@
|
|
1
|
-
// This file was
|
1
|
+
// This file was auto-generated based on version 1.1.0 of the canonical data.
|
2
2
|
|
3
3
|
module TriangleTest
|
4
4
|
|
5
|
-
open Xunit
|
6
5
|
open FsUnit.Xunit
|
6
|
+
open Xunit
|
7
|
+
|
7
8
|
open Triangle
|
8
|
-
open System
|
9
9
|
|
10
10
|
[<Fact>]
|
11
|
-
let ``Equilateral
|
12
|
-
|
11
|
+
let ``Equilateral returns true if all sides are equal`` () =
|
12
|
+
equilateral [2.0; 2.0; 2.0] |> should equal true
|
13
|
+
|
14
|
+
[<Fact(Skip = "Remove to run test")>]
|
15
|
+
let ``Equilateral returns false if any side is unequal`` () =
|
16
|
+
equilateral [2.0; 3.0; 2.0] |> should equal false
|
13
17
|
|
14
18
|
[<Fact(Skip = "Remove to run test")>]
|
15
|
-
let ``
|
16
|
-
|
19
|
+
let ``Equilateral returns false if no sides are equal`` () =
|
20
|
+
equilateral [5.0; 4.0; 6.0] |> should equal false
|
17
21
|
|
18
22
|
[<Fact(Skip = "Remove to run test")>]
|
19
|
-
let ``
|
20
|
-
|
23
|
+
let ``All zero sides are illegal, so the triangle is not equilateral`` () =
|
24
|
+
equilateral [0.0; 0.0; 0.0] |> should equal false
|
21
25
|
|
22
26
|
[<Fact(Skip = "Remove to run test")>]
|
23
|
-
let ``
|
24
|
-
|
27
|
+
let ``Equilateral returns sides may be floats`` () =
|
28
|
+
equilateral [0.5; 0.5; 0.5] |> should equal true
|
25
29
|
|
26
30
|
[<Fact(Skip = "Remove to run test")>]
|
27
|
-
let ``Isosceles
|
28
|
-
|
31
|
+
let ``Isosceles returns true if last two sides are equal`` () =
|
32
|
+
isosceles [3.0; 4.0; 4.0] |> should equal true
|
29
33
|
|
30
34
|
[<Fact(Skip = "Remove to run test")>]
|
31
|
-
let ``Isosceles
|
32
|
-
|
35
|
+
let ``Isosceles returns true if first two sides are equal`` () =
|
36
|
+
isosceles [4.0; 4.0; 3.0] |> should equal true
|
33
37
|
|
34
38
|
[<Fact(Skip = "Remove to run test")>]
|
35
|
-
let ``
|
36
|
-
|
39
|
+
let ``Isosceles returns true if first and last sides are equal`` () =
|
40
|
+
isosceles [4.0; 3.0; 4.0] |> should equal true
|
37
41
|
|
38
42
|
[<Fact(Skip = "Remove to run test")>]
|
39
|
-
let ``
|
40
|
-
|
43
|
+
let ``Equilateral triangles are also isosceles`` () =
|
44
|
+
isosceles [4.0; 4.0; 4.0] |> should equal true
|
41
45
|
|
42
46
|
[<Fact(Skip = "Remove to run test")>]
|
43
|
-
let ``
|
44
|
-
|
47
|
+
let ``Isosceles returns false if no sides are equal`` () =
|
48
|
+
isosceles [2.0; 3.0; 4.0] |> should equal false
|
45
49
|
|
46
50
|
[<Fact(Skip = "Remove to run test")>]
|
47
|
-
let ``
|
48
|
-
|
51
|
+
let ``Sides that violate triangle inequality are not isosceles, even if two are equal`` () =
|
52
|
+
isosceles [1.0; 1.0; 3.0] |> should equal false
|
49
53
|
|
50
54
|
[<Fact(Skip = "Remove to run test")>]
|
51
|
-
let ``
|
52
|
-
|
55
|
+
let ``Isosceles returns sides may be floats`` () =
|
56
|
+
isosceles [0.5; 0.4; 0.5] |> should equal true
|
53
57
|
|
54
58
|
[<Fact(Skip = "Remove to run test")>]
|
55
|
-
let ``
|
56
|
-
|
59
|
+
let ``Scalene returns true if no sides are equal`` () =
|
60
|
+
scalene [5.0; 4.0; 6.0] |> should equal true
|
57
61
|
|
58
62
|
[<Fact(Skip = "Remove to run test")>]
|
59
|
-
let ``
|
60
|
-
|
63
|
+
let ``Scalene returns false if all sides are equal`` () =
|
64
|
+
scalene [4.0; 4.0; 4.0] |> should equal false
|
61
65
|
|
62
66
|
[<Fact(Skip = "Remove to run test")>]
|
63
|
-
let ``
|
64
|
-
|
67
|
+
let ``Scalene returns false if two sides are equal`` () =
|
68
|
+
scalene [4.0; 4.0; 3.0] |> should equal false
|
69
|
+
|
70
|
+
[<Fact(Skip = "Remove to run test")>]
|
71
|
+
let ``Sides that violate triangle inequality are not scalene, even if they are all different`` () =
|
72
|
+
scalene [7.0; 3.0; 2.0] |> should equal false
|
73
|
+
|
74
|
+
[<Fact(Skip = "Remove to run test")>]
|
75
|
+
let ``Scalene returns sides may be floats`` () =
|
76
|
+
scalene [0.5; 0.4; 0.6] |> should equal true
|
77
|
+
|
@@ -789,6 +789,92 @@ type Poker() =
|
|
789
789
|
|
790
790
|
override __.PropertiesWithIdentifier _ = ["input"; "expected"]
|
791
791
|
|
792
|
+
type Pov() =
|
793
|
+
inherit GeneratorExercise()
|
794
|
+
|
795
|
+
let isNull x = match x with null -> true | _ -> false
|
796
|
+
|
797
|
+
override __.RenderSetup _ =
|
798
|
+
["let rec graphToList graph = "
|
799
|
+
" let right ="
|
800
|
+
" graph.children"
|
801
|
+
" |> List.sortBy (fun x -> x.value)"
|
802
|
+
" |> List.collect graphToList"
|
803
|
+
" [graph.value] @ right"
|
804
|
+
"let mapToList graph = match graph with | Some x -> graphToList x | None -> []"
|
805
|
+
] |> String.concat "\n"
|
806
|
+
|
807
|
+
member this.RenderNode (tree: obj) : string =
|
808
|
+
match isNull tree with
|
809
|
+
| true -> ""
|
810
|
+
| false ->
|
811
|
+
let node = (tree :?> JObject).ToObject<Collections.Generic.Dictionary<string, JToken>>();
|
812
|
+
let children =
|
813
|
+
if node.ContainsKey "children" then
|
814
|
+
node.["children"]
|
815
|
+
|> Seq.map this.RenderNode
|
816
|
+
|> formatList
|
817
|
+
else
|
818
|
+
"[]"
|
819
|
+
let label =
|
820
|
+
node.["label"]
|
821
|
+
|> formatValue
|
822
|
+
sprintf "mkGraph %s %s" label children
|
823
|
+
|
824
|
+
override this.RenderArrange canonicalDataCase =
|
825
|
+
seq {
|
826
|
+
yield
|
827
|
+
canonicalDataCase.Properties.["tree"]
|
828
|
+
|> this.RenderNode
|
829
|
+
|> sprintf "let tree = %s"
|
830
|
+
|
831
|
+
match canonicalDataCase.Property, isNull canonicalDataCase.Expected with
|
832
|
+
| "fromPov", false ->
|
833
|
+
yield
|
834
|
+
canonicalDataCase.Expected
|
835
|
+
|> this.RenderNode
|
836
|
+
|> sprintf "let expected = %s"
|
837
|
+
| _, _ -> ()
|
838
|
+
}
|
839
|
+
|> Seq.toList
|
840
|
+
|
841
|
+
|
842
|
+
override __.RenderSut canonicalDataCase =
|
843
|
+
match canonicalDataCase.Property with
|
844
|
+
| "fromPov" ->
|
845
|
+
let from =
|
846
|
+
canonicalDataCase.Properties.["from"]
|
847
|
+
|> formatValue
|
848
|
+
match isNull canonicalDataCase.Expected with
|
849
|
+
| false -> sprintf "fromPOV %s tree |> mapToList " from
|
850
|
+
| true -> sprintf "fromPOV %s tree " from
|
851
|
+
| "pathTo" ->
|
852
|
+
let fromValue =
|
853
|
+
canonicalDataCase.Properties.["from"]
|
854
|
+
|> formatValue
|
855
|
+
let toValue =
|
856
|
+
canonicalDataCase.Properties.["to"]
|
857
|
+
|> formatValue
|
858
|
+
sprintf "tracePathBetween %s %s tree" fromValue toValue
|
859
|
+
| _ -> ""
|
860
|
+
|
861
|
+
override __.RenderExpected (canonicalDataCase, key, value) =
|
862
|
+
match canonicalDataCase.Property with
|
863
|
+
| "fromPov" ->
|
864
|
+
match isNull value with
|
865
|
+
| true -> "None"
|
866
|
+
| false -> sprintf "<| graphToList %s" key
|
867
|
+
| "pathTo" ->
|
868
|
+
match isNull value with
|
869
|
+
| true -> "None"
|
870
|
+
| false ->
|
871
|
+
printf "%s" canonicalDataCase.Description
|
872
|
+
canonicalDataCase.Expected :?> JArray
|
873
|
+
|> Seq.map formatValue
|
874
|
+
|> formatList
|
875
|
+
|> sprintf "<| Some %s"
|
876
|
+
| _ -> ""
|
877
|
+
|
792
878
|
type PrimeFactors() =
|
793
879
|
inherit GeneratorExercise()
|
794
880
|
|
@@ -1065,6 +1151,15 @@ type Sieve() =
|
|
1065
1151
|
type SecretHandshake() =
|
1066
1152
|
inherit GeneratorExercise()
|
1067
1153
|
|
1154
|
+
type SpaceAge() =
|
1155
|
+
inherit GeneratorExercise()
|
1156
|
+
|
1157
|
+
override __.RenderInput (canonicalDataCase, key, value) =
|
1158
|
+
match value with
|
1159
|
+
| :? string as s -> s
|
1160
|
+
| :? int64 as i -> sprintf "%dL" i
|
1161
|
+
| _ -> base.RenderInput (canonicalDataCase, key, value)
|
1162
|
+
|
1068
1163
|
type SpiralMatrix() =
|
1069
1164
|
inherit GeneratorExercise()
|
1070
1165
|
|
@@ -1088,6 +1183,32 @@ type TwelveDays() =
|
|
1088
1183
|
|> Seq.map formatValue
|
1089
1184
|
|> formatMultiLineList
|
1090
1185
|
|
1186
|
+
type Triangle() =
|
1187
|
+
inherit GeneratorExercise()
|
1188
|
+
|
1189
|
+
let formatFloat (value:obj) =
|
1190
|
+
match value with
|
1191
|
+
| :? int64 as i -> sprintf "%.1f" (float i)
|
1192
|
+
| :? int32 as i -> sprintf "%.1f" (float i)
|
1193
|
+
| :? float as f -> sprintf "%.1f" f
|
1194
|
+
| _ -> failwith "Invalid value"
|
1195
|
+
|
1196
|
+
let hasUniqueTestMethodName canonicalDataCase =
|
1197
|
+
canonicalDataCase.Description.Contains "equilateral" ||
|
1198
|
+
canonicalDataCase.Description.Contains "isosceles" ||
|
1199
|
+
canonicalDataCase.Description.Contains "scalene"
|
1200
|
+
|
1201
|
+
override __.RenderTestMethodName canonicalDataCase =
|
1202
|
+
match hasUniqueTestMethodName canonicalDataCase with
|
1203
|
+
| true -> base.RenderTestMethodName canonicalDataCase
|
1204
|
+
| false -> sprintf "%s returns %s" (String.upperCaseFirst canonicalDataCase.Property) canonicalDataCase.Description
|
1205
|
+
|
1206
|
+
override __.RenderInput (_, _, value) =
|
1207
|
+
value :?> JArray
|
1208
|
+
|> normalizeJArray
|
1209
|
+
|> Seq.map formatFloat
|
1210
|
+
|> formatList
|
1211
|
+
|
1091
1212
|
type TwoFer() =
|
1092
1213
|
inherit GeneratorExercise()
|
1093
1214
|
|