Skip to content

Commit e775e52

Browse files
Enable Hamming test generator (#551)
This can now be enabled now that the "reimplements" key is honoured.
1 parent 8429580 commit e775e52

File tree

4 files changed

+14
-109
lines changed

4 files changed

+14
-109
lines changed

exercises/practice/hamming/.meta/example.ml

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,11 @@ open Base
22

33
type nucleotide = A | C | G | T
44

5-
let equal (x,y) = match (x, y) with
6-
| (A, A) -> true
7-
| (C, C) -> true
8-
| (G, G) -> true
9-
| (T, T) -> true
10-
| _ -> false
11-
12-
let to_result (l: 'a List.Or_unequal_lengths.t): ('a, string) Result.t =
13-
let open List.Or_unequal_lengths in
14-
match l with
15-
| Unequal_lengths -> Error "left and right strands must be of equal length"
16-
| Ok x -> Ok x
5+
let equal (x, y) = match (x, y) with
6+
| (A, A) | (C, C) | (G, G) | (T, T) -> true
7+
| _ -> false
178

189
let hamming_distance a b =
19-
match (List.is_empty a, List.is_empty b) with
20-
| (true, false) -> Error "left strand must not be empty"
21-
| (false, true) -> Error "right strand must not be empty"
22-
| _ -> List.zip a b |> to_result |> Result.map ~f:(List.count ~f:(Fn.non equal))
23-
10+
match List.zip a b with
11+
| Unequal_lengths -> Error "strands must be of equal length"
12+
| Ok pairs -> Ok (List.count pairs ~f:(Fn.non equal))
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
(lang dune 1.1)
2-
(version 2.3.0)
2+
(version 1.0)

exercises/practice/hamming/test.ml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(* hamming - 2.3.0 *)
1+
(* hamming - 1.0 *)
22
open Base
33
open OUnit2
44
open Hamming
@@ -32,13 +32,13 @@ let tests = [
3232
"long different strands" >::
3333
ae (Ok 9) (hamdist "GGACGGATTCTG" "AGGACGGATTCT");
3434
"disallow first strand longer" >::
35-
ae (Error "left and right strands must be of equal length") (hamdist "AATG" "AAA");
35+
ae (Error "strands must be of equal length") (hamdist "AATG" "AAA");
3636
"disallow second strand longer" >::
37-
ae (Error "left and right strands must be of equal length") (hamdist "ATA" "AGTG");
38-
"disallow left empty strand" >::
39-
ae (Error "left strand must not be empty") (hamdist "" "G");
40-
"disallow right empty strand" >::
41-
ae (Error "right strand must not be empty") (hamdist "G" "");
37+
ae (Error "strands must be of equal length") (hamdist "ATA" "AGTG");
38+
"disallow empty first strand" >::
39+
ae (Error "strands must be of equal length") (hamdist "" "G");
40+
"disallow empty second strand" >::
41+
ae (Error "strands must be of equal length") (hamdist "G" "");
4242
]
4343

4444
let () =

templates/hamming/.broken

Lines changed: 0 additions & 84 deletions
This file was deleted.

0 commit comments

Comments
 (0)