trackler 2.0.3.2 → 2.0.3.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) hide show
  1. checksums.yaml +4 -4
  2. data/lib/trackler/version.rb +1 -1
  3. data/tracks/c/config.json +10 -0
  4. data/tracks/c/exercises/robot-simulator/makefile +16 -0
  5. data/tracks/c/exercises/robot-simulator/src/example.c +74 -0
  6. data/tracks/c/exercises/robot-simulator/src/robot_simulator.h +41 -0
  7. data/tracks/c/exercises/robot-simulator/test/test_robot_simulator.c +165 -0
  8. data/tracks/c/exercises/robot-simulator/test/vendor/unity.c +1300 -0
  9. data/tracks/c/exercises/robot-simulator/test/vendor/unity.h +274 -0
  10. data/tracks/c/exercises/robot-simulator/test/vendor/unity_internals.h +701 -0
  11. data/tracks/ecmascript/exercises/rna-transcription/example.js +9 -2
  12. data/tracks/ecmascript/exercises/rna-transcription/rna-transcription.spec.js +18 -0
  13. data/tracks/go/exercises/hello-world/example.go +4 -2
  14. data/tracks/go/exercises/hello-world/hello_test.go +4 -4
  15. data/tracks/go/exercises/hello-world/hello_world.go +6 -6
  16. data/tracks/groovy/config.json +5 -0
  17. data/tracks/groovy/exercises/phone-number/Example.groovy +20 -0
  18. data/tracks/groovy/exercises/phone-number/PhoneNumberSpec.groovy +75 -0
  19. data/tracks/haskell/exercises/difference-of-squares/test/Tests.hs +2 -0
  20. data/tracks/java/config.json +13 -1
  21. data/tracks/java/exercises/all-your-base/build.gradle +17 -0
  22. data/tracks/java/exercises/all-your-base/src/example/java/BaseConverter.java +80 -0
  23. data/tracks/java/exercises/all-your-base/src/main/java/BaseConverter.java +5 -0
  24. data/tracks/java/exercises/all-your-base/src/test/java/BaseConverterTest.java +256 -0
  25. data/tracks/java/exercises/binary-search/build.gradle +17 -0
  26. data/tracks/java/exercises/binary-search/src/example/java/BinarySearch.java +40 -0
  27. data/tracks/java/exercises/binary-search/src/main/java/.keep +0 -0
  28. data/tracks/java/exercises/binary-search/src/main/java/BinarySearch.java +4 -0
  29. data/tracks/java/exercises/binary-search/src/test/java/.keep +0 -0
  30. data/tracks/java/exercises/binary-search/src/test/java/BinarySearchTest.java +136 -0
  31. data/tracks/java/exercises/settings.gradle +1 -0
  32. data/tracks/lua/config.json +16 -0
  33. data/tracks/lua/exercises/say/example.lua +92 -0
  34. data/tracks/lua/exercises/say/say_spec.lua +105 -0
  35. data/tracks/lua/exercises/secret-handshake/example.lua +17 -0
  36. data/tracks/lua/exercises/secret-handshake/secret-handshake_spec.lua +38 -0
  37. data/tracks/ocaml/config.json +10 -1
  38. data/tracks/ocaml/exercises/bracket-push/.merlin +3 -0
  39. data/tracks/ocaml/exercises/bracket-push/Makefile +11 -0
  40. data/tracks/ocaml/exercises/bracket-push/bracket_push.mli +3 -0
  41. data/tracks/ocaml/exercises/bracket-push/example.ml +40 -0
  42. data/tracks/ocaml/exercises/bracket-push/test.ml +38 -0
  43. data/tracks/ocaml/exercises/leap/test.ml +7 -7
  44. data/tracks/ocaml/tools/test-generator/Makefile +2 -2
  45. data/tracks/ocaml/tools/test-generator/interfaces/codegen.mli +2 -2
  46. data/tracks/ocaml/tools/test-generator/interfaces/{test_generator.mli → controller.mli} +0 -0
  47. data/tracks/ocaml/tools/test-generator/interfaces/parser.mli +7 -1
  48. data/tracks/ocaml/tools/test-generator/interfaces/special_cases.mli +2 -2
  49. data/tracks/ocaml/tools/test-generator/interfaces/utils.mli +4 -0
  50. data/tracks/ocaml/tools/test-generator/src/codegen.ml +9 -5
  51. data/tracks/ocaml/tools/test-generator/src/{test_generator.ml → controller.ml} +24 -15
  52. data/tracks/ocaml/tools/test-generator/src/model.ml +6 -0
  53. data/tracks/ocaml/tools/test-generator/src/parser.ml +34 -7
  54. data/tracks/ocaml/tools/test-generator/src/special_cases.ml +11 -4
  55. data/tracks/ocaml/tools/test-generator/src/template.ml +49 -6
  56. data/tracks/ocaml/tools/test-generator/src/test_gen.ml +1 -1
  57. data/tracks/ocaml/tools/test-generator/src/utils.ml +6 -0
  58. data/tracks/ocaml/tools/test-generator/templates/anagram/template.ml +2 -2
  59. data/tracks/ocaml/tools/test-generator/templates/bob/template.ml +2 -2
  60. data/tracks/ocaml/tools/test-generator/templates/bracket-push/template.ml +16 -0
  61. data/tracks/ocaml/tools/test-generator/templates/difference-of-squares/template.ml +19 -0
  62. data/tracks/ocaml/tools/test-generator/templates/hamming/template.ml +2 -2
  63. data/tracks/ocaml/tools/test-generator/templates/hello-world/template.ml +2 -2
  64. data/tracks/ocaml/tools/test-generator/templates/leap/template.ml +2 -2
  65. data/tracks/ocaml/tools/test-generator/templates/raindrops/template.ml +2 -2
  66. data/tracks/ocaml/tools/test-generator/templates/say/template.ml +3 -3
  67. data/tracks/ocaml/tools/test-generator/templates/word-count/template.ml +2 -2
  68. data/tracks/ocaml/tools/test-generator/test/all_tests.ml +3 -1
  69. data/tracks/ocaml/tools/test-generator/test/codegen_test.ml +7 -7
  70. data/tracks/ocaml/tools/test-generator/test/difference_of_squares.json +67 -0
  71. data/tracks/ocaml/tools/test-generator/test/hello_world.json +23 -0
  72. data/tracks/ocaml/tools/test-generator/test/parser_test.ml +30 -12
  73. data/tracks/ocaml/tools/test-generator/test/sample-suite-template.txt +16 -0
  74. data/tracks/ocaml/tools/test-generator/test/sample_template.txt +2 -2
  75. data/tracks/ocaml/tools/test-generator/test/special_cases_test.ml +1 -1
  76. data/tracks/ocaml/tools/test-generator/test/template_test.ml +40 -6
  77. data/tracks/perl6/.travis.yml +3 -0
  78. data/tracks/perl6/docs/RESOURCES.md +1 -1
  79. data/tracks/perl6/exercises/accumulate/accumulate.t +3 -7
  80. data/tracks/perl6/exercises/anagram/anagram.t +3 -7
  81. data/tracks/perl6/exercises/binary/binary.t +3 -7
  82. data/tracks/perl6/exercises/bob/bob.t +4 -8
  83. data/tracks/perl6/exercises/grains/grains.t +3 -7
  84. data/tracks/perl6/exercises/leap/leap.t +3 -7
  85. data/tracks/perl6/exercises/rna-transcription/rna_transcription.t +4 -8
  86. data/tracks/perl6/exercises/robot-name/robot.t +4 -8
  87. data/tracks/perl6/exercises/scrabble-score/scrabble_score.t +3 -7
  88. data/tracks/perl6/exercises/word-count/word_count.t +3 -8
  89. data/tracks/r/config.json +10 -0
  90. data/tracks/r/docs/ABOUT.md +14 -0
  91. data/tracks/r/exercises/difference-of-squares/difference-of-squares.R +5 -0
  92. data/tracks/r/exercises/difference-of-squares/example.R +6 -0
  93. data/tracks/r/exercises/difference-of-squares/test_difference-of-squares.R +23 -0
  94. data/tracks/r/exercises/hamming/example.R +8 -0
  95. data/tracks/r/exercises/hamming/hamming.R +4 -0
  96. data/tracks/r/exercises/hamming/test_hamming.R +87 -0
  97. data/tracks/ruby/exercises/binary/.version +1 -1
  98. data/tracks/ruby/exercises/binary/binary_test.rb +17 -19
  99. data/tracks/ruby/exercises/binary/example.rb +13 -13
  100. data/tracks/ruby/exercises/isogram/.version +1 -1
  101. data/tracks/ruby/exercises/isogram/example.rb +1 -1
  102. data/tracks/ruby/exercises/isogram/isogram_test.rb +16 -30
  103. data/tracks/ruby/lib/binary_cases.rb +2 -3
  104. data/tracks/ruby/lib/isogram_cases.rb +1 -5
  105. data/tracks/scala/exercises/phone-number/HINTS.md +9 -0
  106. metadata +45 -4
@@ -0,0 +1,16 @@
1
+ open Core.Std
2
+ open OUnit2
3
+ open Difference_of_squares
4
+
5
+ let ae exp got _test_ctxt = assert_equal exp got
6
+
7
+ let (* SUITE *)$(suite_name)_tests = [
8
+ (* TEST
9
+ "$description" >::
10
+ ae $expected ($suite-name $number);
11
+ END TEST *)
12
+ ]
13
+ (* END SUITE *)
14
+
15
+ let () =
16
+ run_test_tt_main ("difference of squares tests" >::: List.concat [(* suite-all-names *)])
@@ -5,9 +5,9 @@ open Hello_world
5
5
  let ae exp got _test_ctxt = assert_equal ~printer:String.to_string exp got
6
6
 
7
7
  let tests = [
8
- (* GENERATED-CODE
8
+ (* TEST
9
9
  code
10
- END GENERATED-CODE *)
10
+ END TEST *)
11
11
  ]
12
12
 
13
13
  let () =
@@ -15,7 +15,7 @@ let stringify = function
15
15
 
16
16
  let special_cases_tests = [
17
17
  "for a non special cased slug convert the parameter to a string" >:: (fun _ctx ->
18
- assert_equal ~printer:Fn.id "stringified" @@ fixup ~stringify ~slug:"some-slug" ~key:"key" ~value:(Bool true)
18
+ assert_equal ~printer:Fn.id "stringified" @@ edit_expected ~stringify ~slug:"some-slug" ~value:(Bool true)
19
19
  );
20
20
 
21
21
  "an optional int parameter is converted to none if it matches the special value" >:: (fun _ctx ->
@@ -4,23 +4,57 @@ open Codegen
4
4
  open Template
5
5
 
6
6
  let printer = Option.value_map ~f:show ~default:"None"
7
+ let int_option_printer = Option.value_map ~f:Int.to_string ~default:"None"
7
8
 
8
9
  let template_tests = [
9
- "if there is no generated code marker in a string then find_template returns None" >:: (fun _ctx ->
10
+ "if there is no test marker in a string then find_template returns None" >:: (fun _ctx ->
10
11
  assert_equal None @@ find_template ~template_text:"some code block"
11
12
  );
12
13
 
13
- "if there is generated code marker in a string then find_template returns where it is" >:: (fun _ctx ->
14
+ "if there is a test marker in a string then find_template returns where it is" >:: (fun _ctx ->
14
15
  let template_text = In_channel.read_all "test/sample_template.txt" in
15
- assert_equal ~printer (Some {start=7; finish=9; file_text=template_text; template="code"}) @@ find_template ~template_text
16
+ assert_equal ~printer (Some {start=7; finish=9;
17
+ file_text=template_text; template="code";
18
+ suite_name_line= None;
19
+ suite_end = None;
20
+ suite_all_names_line = None}) @@ find_template ~template_text
21
+ );
22
+
23
+ "if there is a suite description line then find_template returns where it is" >:: (fun _ctx ->
24
+ let template_text = In_channel.read_all "test/sample-suite-template.txt" in
25
+ let template = find_template ~template_text in
26
+ match template with
27
+ | None -> assert_failure "Could not find a template at all"
28
+ | Some template -> assert_equal ~printer:int_option_printer (Some 6) template.suite_name_line
29
+ );
30
+
31
+ "if there is a suite all descriptions line then find_template returns where it is" >:: (fun _ctx ->
32
+ let template_text = In_channel.read_all "test/sample-suite-template.txt" in
33
+ let template = find_template ~template_text in
34
+ match template with
35
+ | None -> assert_failure "Could not find a template at all"
36
+ | Some template -> assert_equal ~printer:int_option_printer (Some 15) template.suite_all_names_line
16
37
  );
17
38
 
18
39
  "fills in lines of a template" >:: (fun _ctx ->
19
40
  let template_text = In_channel.read_all "test/sample_template.txt" in
20
- let template = {start=7; finish=9; file_text=template_text;template="code"} in
21
- let filled = fill template [Subst "line1"; Subst "line2"] in
22
- let pattern = " (* GENERATED-CODE\ncode\n END GENERATED-CODE *)" in
41
+ let template = {start=7; finish=9; file_text=template_text;template="code";
42
+ suite_name_line= None; suite_end = None; suite_all_names_line = None} in
43
+ let filled = fill_tests template [Subst "line1"; Subst "line2"] in
44
+ let pattern = " (* TEST\ncode\n END TEST *)" in
23
45
  let expected = (String.substr_replace_all ~pattern ~with_:"line1\nline2" template_text) in
24
46
  assert_equal ~printer:Fn.id expected (filled ^ "\n")
25
47
  );
48
+
49
+ "fills in a single suite in a suite template" >:: (fun _ctx ->
50
+ let template_text = In_channel.read_all "test/sample-suite-template.txt" in
51
+ let template = {start=7; finish=9; file_text=template_text;template="code";
52
+ suite_name_line=Some 6; suite_end = Some 14; suite_all_names_line = None} in
53
+ let subst = ("tests1", [Subst "line1"; Subst "line2"]) in
54
+ let filled = fill_single_suite template subst in
55
+ assert_equal ~printer:Bool.to_string true (String.substr_index filled ~pattern:"let tests1_tests = [" |> Option.is_some);
56
+ assert_equal ~printer:Bool.to_string true (String.substr_index filled ~pattern:"line1" |> Option.is_some);
57
+ assert_equal ~printer:Bool.to_string true (String.substr_index filled ~pattern:"line2" |> Option.is_some);
58
+ assert_equal ~printer:Int.to_string 6 (String.count ~f:(fun ch -> ch = '\n') filled);
59
+ );
26
60
  ]
@@ -5,6 +5,9 @@ perl6:
5
5
  - latest
6
6
  - '2016.10'
7
7
  - '2016.07'
8
+ install:
9
+ - rakudobrew build-panda
10
+ - panda install JSON::Tiny
8
11
  before_script:
9
12
  - bin/fetch-configlet
10
13
  script:
@@ -1,3 +1,3 @@
1
1
  # Resources
2
2
 
3
- * [The Perl6 site](https://perl6.org/) has a [resources](https://perl6.org/resources/) page containing variety of information on the language, such as guides for newcomers, documentation, and screencasts.
3
+ [The Perl6 site](https://perl6.org/) has a [resources](https://perl6.org/resources/) page containing variety of information on the language, such as guides for newcomers, documentation, and screencasts.
@@ -3,14 +3,10 @@ use v6;
3
3
  use Test;
4
4
  use lib IO::Path.new($?FILE).parent.path;
5
5
 
6
- plan 8;
7
-
8
6
  BEGIN {
9
- my $module = %*ENV{'EXERCISM'} ?? 'Example' !! 'Accumulate';
10
- EVAL("use $module")
11
- };
12
-
13
- pass 'Load module';
7
+ plan 8;
8
+ eval-lives-ok %*ENV<EXERCISM>.so ?? 'use Example' !! 'use Accumulate', 'Module loaded';
9
+ }
14
10
 
15
11
  ok Accumulate.can('accumulate'), 'Accumulate class has accumulate() method';
16
12
 
@@ -3,14 +3,10 @@ use v6;
3
3
  use Test;
4
4
  use lib IO::Path.new($?FILE).parent.path;
5
5
 
6
- plan 11;
7
-
8
6
  BEGIN {
9
- my $module = %*ENV{'EXERCISM'} ?? 'Example' !! 'Anagram';
10
- EVAL("use $module")
11
- };
12
-
13
- pass 'Load module';
7
+ plan 11;
8
+ eval-lives-ok %*ENV<EXERCISM>.so ?? 'use Example' !! 'use Anagram', 'Module loaded';
9
+ }
14
10
 
15
11
  ok Anagram.can('match'), 'Class Anagram has match method';
16
12
 
@@ -3,14 +3,10 @@ use v6;
3
3
  use Test;
4
4
  use lib IO::Path.new($?FILE).parent.path;
5
5
 
6
- plan 10;
7
-
8
6
  BEGIN {
9
- my $module = %*ENV{'EXERCISM'} ?? 'Example' !! 'Binary';
10
- EVAL("use $module")
11
- };
12
-
13
- pass 'Load module';
7
+ plan 10;
8
+ eval-lives-ok %*ENV<EXERCISM>.so ?? 'use Example' !! 'use Binary', 'Module loaded';
9
+ }
14
10
 
15
11
  ok Binary.can('to_decimal'), 'Class Binary has to_decimal method';
16
12
 
@@ -3,14 +3,10 @@ use v6;
3
3
  use Test;
4
4
  use lib IO::Path.new($?FILE).parent.path;
5
5
 
6
- plan 21;
7
-
8
- BEGIN {
9
- my $module = %*ENV{'EXERCISM'} ?? 'Example' !! 'Bob';
10
- EVAL("use $module");
11
- };
12
-
13
- pass 'Load module';
6
+ BEGIN {
7
+ plan 21;
8
+ eval-lives-ok %*ENV<EXERCISM>.so ?? 'use Example' !! 'use Bob', 'Module loaded';
9
+ }
14
10
 
15
11
  ok Bob.can('hey'), 'Class Bob has hey() method';
16
12
 
@@ -3,14 +3,10 @@ use v6;
3
3
  use Test;
4
4
  use lib IO::Path.new($?FILE).parent.path;
5
5
 
6
- plan 11;
7
-
8
6
  BEGIN {
9
- my $module = %*ENV{'EXERCISM'} ?? 'Example' !! 'Grains';
10
- EVAL("use $module")
11
- };
12
-
13
- pass 'Load module';
7
+ plan 11;
8
+ eval-lives-ok %*ENV<EXERCISM>.so ?? 'use Example' !! 'use Grains', 'Module loaded';
9
+ }
14
10
 
15
11
  ok Grains.can('square'), 'Grains class has square method';
16
12
  ok Grains.can('total'), 'Grains class has total method';
@@ -3,14 +3,10 @@ use v6;
3
3
  use Test;
4
4
  use lib IO::Path.new($?FILE).parent.path;
5
5
 
6
- plan 8;
7
-
8
6
  BEGIN {
9
- my $module = %*ENV{'EXERCISM'} ?? 'Example' !! 'Leap';
10
- EVAL("use $module");
11
- };
12
-
13
- pass 'Load module';
7
+ plan 8;
8
+ eval-lives-ok %*ENV<EXERCISM>.so ?? 'use Example' !! 'use Leap', 'Module loaded';
9
+ }
14
10
 
15
11
  ok Leap.can('is_leap'), 'Leap class has is_leap() method';
16
12
 
@@ -3,14 +3,10 @@ use v6;
3
3
  use Test;
4
4
  use lib IO::Path.new($?FILE).parent.path;
5
5
 
6
- plan 7;
7
-
8
- BEGIN {
9
- my $module = %*ENV{'EXERCISM'} ?? 'Example' !! 'RNA_Transcription';
10
- EVAL("use $module");
11
- };
12
-
13
- pass 'Load module';
6
+ BEGIN {
7
+ plan 7;
8
+ eval-lives-ok %*ENV<EXERCISM>.so ?? 'use Example' !! 'use RNA_Transcription', 'Module loaded';
9
+ }
14
10
 
15
11
  ok RNA_Transcription.can('to_rna'), 'Class RNA_Transcription has to_rna() method';
16
12
 
@@ -3,14 +3,10 @@ use v6;
3
3
  use Test;
4
4
  use lib IO::Path.new($?FILE).parent.path;
5
5
 
6
- plan 7;
7
-
8
- BEGIN {
9
- my $module = %*ENV{'EXERCISM'} ?? 'Example' !! 'Robot';
10
- EVAL("use $module");
11
- };
12
-
13
- pass 'Load module';
6
+ BEGIN {
7
+ plan 7;
8
+ eval-lives-ok %*ENV<EXERCISM>.so ?? 'use Example' !! 'use Robot', 'Module loaded';
9
+ }
14
10
 
15
11
  ok Robot.can('name'), 'Robot class has name attribute';
16
12
  ok Robot.can('reset_name'), 'Robot class has reset_name method';
@@ -3,14 +3,10 @@ use v6;
3
3
  use Test;
4
4
  use lib IO::Path.new($?FILE).parent.path;
5
5
 
6
- plan 10;
7
-
8
6
  BEGIN {
9
- my $module = %*ENV{'EXERCISM'} ?? 'Example' !! 'Scrabble';
10
- EVAL("use $module")
11
- };
12
-
13
- pass 'Load module';
7
+ plan 10;
8
+ eval-lives-ok %*ENV<EXERCISM>.so ?? 'use Example' !! 'use Scrabble', 'Module loaded';
9
+ }
14
10
 
15
11
  ok Scrabble.can('score'), 'Scrabble class has score() method';
16
12
 
@@ -3,15 +3,10 @@ use v6;
3
3
  use Test;
4
4
  use lib IO::Path.new($?FILE).parent.path;
5
5
 
6
- plan 8;
7
-
8
6
  BEGIN {
9
- my $module = %*ENV{'EXERCISM'} ?? 'Example' !! 'Word_Counter';
10
- EVAL("use $module")
11
- };
12
-
13
- pass 'Load module';
14
-
7
+ plan 8;
8
+ eval-lives-ok %*ENV<EXERCISM>.so ?? 'use Example' !! 'use Word_Counter', 'Module loaded';
9
+ }
15
10
 
16
11
  ok Word_Counter.can('count_words'), 'Class Word_Counter has count_words method';
17
12
 
data/tracks/r/config.json CHANGED
@@ -44,6 +44,16 @@
44
44
  "difficulty": 1,
45
45
  "slug": "word-count",
46
46
  "topics": []
47
+ },
48
+ {
49
+ "difficulty": 1,
50
+ "slug": "difference-of-squares",
51
+ "topics": []
52
+ },
53
+ {
54
+ "difficulty": 1,
55
+ "slug": "hamming",
56
+ "topics": []
47
57
  }
48
58
  ]
49
59
  }
@@ -0,0 +1,14 @@
1
+ R is a free, open source, programming language and software environment for statistical computing and graphics developed at Bell Laboratories as a GNU project. It is designed as a true computer language, and is written in C, Fortran and R.
2
+
3
+ R provides a wide variety of statistical (linear and nonlinear modelling, classical statistical tests, time-series analysis, classification, clustering, etc) and graphical techniques, and is highly extensible.
4
+
5
+ One of its strengths is the ease with which well-designed publication-quality plots can be produced, including mathematical symbols and formulae where needed. Great care has been taken over the defaults for the minor design choices in graphics, but the user retains full control. Along with this, for computationally-intensive tasks, C, C++ and Fortran can be linked and called at runtime or one can even write C code to manipulate R objects directly.
6
+
7
+ The R software suite includes:
8
+ * An effective data handling and storage facility,
9
+ * A suite of operators for calculations on arrays, in particular matrices,
10
+ * A large, coherent, integrated collection of intermediate tools for data analysis,
11
+ * graphical facilities for data analysis and display either on-screen or on hardcopy, and
12
+ * A well-developed, simple and effective programming language which includes conditionals, loops, user-defined recursive functions and input and output facilities.
13
+ * The term “environment” is intended to characterize it as a fully planned and coherent system, rather than an incremental accretion of very specific and inflexible tools, as is frequently the case with other data analysis software.
14
+ * R can be extended (easily) via packages. There are about eight packages supplied with the R distribution and many more are available through the CRAN family of Internet sites covering a very wide range of modern statistics.
@@ -0,0 +1,5 @@
1
+ # this is a stub function that takes a natural_number
2
+ # and should return the difference-of-squares as described
3
+ # in the README.md
4
+ difference_of_squares <- function(natural_number) {
5
+ }
@@ -0,0 +1,6 @@
1
+ difference_of_squares <- function(natural_number) {
2
+ num_sequence <- seq_len(natural_number)
3
+ square_sums <- sum(num_sequence)^2
4
+ sum_squares <- sum(num_sequence^2)
5
+ sum(square_sums - sum_squares)
6
+ }
@@ -0,0 +1,23 @@
1
+ source('./difference-of-squares.R')
2
+ suppressPackageStartupMessages({ require(testthat) })
3
+
4
+ test_that("difference of squares 0", {
5
+ input <- 0
6
+ expect_equal(difference_of_squares(input), 0)
7
+ })
8
+
9
+ test_that("difference of squares 5", {
10
+ input <- 5
11
+ expect_equal(difference_of_squares(input), 170)
12
+ })
13
+
14
+ test_that("difference of squares 10", {
15
+ input <- 10
16
+ expect_equal(difference_of_squares(input), 2640)
17
+ })
18
+
19
+ test_that("difference of squares 100", {
20
+ input <- 100
21
+ expect_equal(difference_of_squares(input), 25164150)
22
+ })
23
+
@@ -0,0 +1,8 @@
1
+ hamming <- function(strand1,strand2) {
2
+ if (nchar(strand1) != nchar(strand2)) {
3
+ stop("undefined hamming distance")
4
+ }
5
+ strand1 <- strsplit(strand1,"")[[1]]
6
+ strand2 <- strsplit(strand2,"")[[1]]
7
+ length(strand1) - sum(strand1 == strand2)
8
+ }
@@ -0,0 +1,4 @@
1
+ # This is a stub function to take two strings
2
+ # and calculate the hamming distance
3
+ hamming <- function(strand1,strand2) {
4
+ }
@@ -0,0 +1,87 @@
1
+ source('./hamming.R')
2
+ suppressPackageStartupMessages({ require(testthat) })
3
+
4
+ test_that("identical strands", {
5
+ strand1 <-"A"
6
+ strand2 <- "A"
7
+ expect_equal(hamming(strand1, strand2), 0)
8
+ })
9
+
10
+ test_that("long identical strands", {
11
+ strand1 <-"GGACTGA"
12
+ strand2 <- "GGACTGA"
13
+ expect_equal(hamming(strand1, strand2), 0)
14
+ })
15
+
16
+ test_that("complete distance in single nucleotide strands", {
17
+ strand1 <-"A"
18
+ strand2 <- "G"
19
+ expect_equal(hamming(strand1, strand2), 1)
20
+ })
21
+
22
+ test_that("complete distance in small strands", {
23
+ strand1 <-"AG"
24
+ strand2 <- "CT"
25
+ expect_equal(hamming(strand1, strand2), 2)
26
+ })
27
+
28
+ test_that("small distance in small strands", {
29
+ strand1 <-"AT"
30
+ strand2 <- "CT"
31
+ expect_equal(hamming(strand1, strand2), 1)
32
+ })
33
+
34
+ test_that("small distance", {
35
+ strand1 <-"GGACG"
36
+ strand2 <- "GGTCG"
37
+ expect_equal(hamming(strand1, strand2), 1)
38
+ })
39
+
40
+ test_that("small distance in long strands", {
41
+ strand1 <-"ACCAGGG"
42
+ strand2 <- "ACTATGG"
43
+ expect_equal(hamming(strand1, strand2), 2)
44
+ })
45
+
46
+ test_that("non-unique character in first strand", {
47
+ strand1 <-"AGA"
48
+ strand2 <- "AGG"
49
+ expect_equal(hamming(strand1, strand2), 1)
50
+ })
51
+
52
+ test_that("non-unique character in second strand", {
53
+ strand1 <-"AGG"
54
+ strand2 <- "AGA"
55
+ expect_equal(hamming(strand1, strand2), 1)
56
+ })
57
+
58
+ test_that("same nucleotides in different positions", {
59
+ strand1 <-"TAG"
60
+ strand2 <- "GAT"
61
+ expect_equal(hamming(strand1, strand2), 2)
62
+ })
63
+
64
+ test_that("large distance", {
65
+ strand1 <-"GATACA"
66
+ strand2 <- "GCATAA"
67
+ expect_equal(hamming(strand1, strand2), 4)
68
+ })
69
+
70
+ test_that("empty strands", {
71
+ strand1 <-""
72
+ strand2 <- ""
73
+ expect_equal(hamming(strand1, strand2), 0)
74
+ })
75
+
76
+ test_that("disallow first strand longer", {
77
+ strand1 <-"AATG"
78
+ strand2 <- "AAA"
79
+ expect_error(hamming(strand1, strand2))
80
+ })
81
+
82
+ test_that("disallow second strand longer", {
83
+ strand1 <-"ATA"
84
+ strand2 <- "AGTG"
85
+ expect_error(hamming(strand1, strand2))
86
+ })
87
+