<commit_before>(* Exercise 1. eval formula *)
open Ex1
open Testlib

module TestEx1: TestEx =
  struct
    let exnum = 1

    type testcase =
      | EVAL of formula * bool

    let runner tc =
      match tc with
      | EVAL (f, b) -> eval f = b

    let testcases =
      [ EVAL (TRUE, true)
      ; EVAL (FALSE, false)
      ; EVAL (NOT TRUE, false)
      ; EVAL (NOT FALSE, true)
      ; EVAL (ANDALSO (TRUE, TRUE), true)
      ; EVAL (ANDALSO (TRUE, FALSE), false)
      ; EVAL (ANDALSO (FALSE, TRUE), false)
      ; EVAL (ANDALSO (FALSE, FALSE), false)
      ; EVAL (ORELSE (TRUE, TRUE), true)
      ; EVAL (ORELSE (TRUE, FALSE), true)
      ; EVAL (ORELSE (FALSE, TRUE), true)
      ; EVAL (ORELSE (FALSE, FALSE), false)
      ; EVAL (IMPLY (TRUE, TRUE), true)
      ; EVAL (IMPLY (TRUE, FALSE), false)
      ; EVAL (IMPLY (FALSE, TRUE), true)
      ; EVAL (IMPLY (FALSE, FALSE), true)
      ; EVAL (LESS (NUM 1, NUM 2), true)
      ; EVAL (LESS (NUM 2, NUM 1), false)
      ; EVAL (LESS (NUM (-100), NUM (-200)), false)
      ; EVAL (LESS (NUM (-200), NUM (-100)), true)
      ; EVAL (LESS (NUM (-10000), NUM 10000), true)
      ; EVAL (LESS (NUM 10000, NUM (-10000)), false)
      ; EVAL (LESS (PLUS (NUM 1, NUM 2), NUM 3), false)
      ; EVAL (LESS (PLUS (NUM 1, NUM 2), NUM 4), true)
      ; EVAL (LESS (MINUS (NUM 10, NUM 5), NUM 5), false)
      ; EVAL (LESS (MINUS (NUM 10, NUM 5), NUM 6), true)
      ; EVAL (LESS (PLUS (NUM (-12345), NUM 23456), NUM 11111), false)
      ; EVAL (LESS (PLUS (NUM (-12345), NUM 23456), NUM 11112), true)
      ; EVAL (LESS (MINUS (NUM 12345, NUM 23456), NUM (-11111)), false)
      ; EVAL (LESS (MINUS (NUM 12345, NUM 23456), NUM (-11110)), true)
      ]
  end

open TestEx1
let _ = wrapper testcases runner exnum<commit_msg>Implement string_of_tc in 2-1<commit_after>(* Exercise 1. eval formula *)
open Ex1
open Testlib
open Printf

let rec string_of_expr e =
  match e with
  | NUM n -> string_of_int n
  | PLUS (e1, e2) -> sprintf "(%s) + (%s)" (string_of_expr e1) (string_of_expr e2)
  | MINUS (e1, e2) -> sprintf "(%s) - (%s)" (string_of_expr e1) (string_of_expr e2)

let rec string_of_fomula f =
  match f with
  | TRUE -> "true"
  | FALSE -> "false"
  | NOT f' -> sprintf "not (%s)" (string_of_fomula f')
  | ANDALSO (f1, f2) -> sprintf "(%s) && (%s)" (string_of_fomula f1) (string_of_fomula f2)
  | ORELSE (f1, f2) -> sprintf "(%s) || (%s)" (string_of_fomula f1) (string_of_fomula f2)
  | IMPLY (f1, f2) -> sprintf "(%s) -> (%s)" (string_of_fomula f1) (string_of_fomula f2)
  | LESS (e1, e2) -> sprintf "%s < %s" (string_of_expr e1) (string_of_expr e2)

module TestEx1: TestEx =
  struct
    let exnum = 1

    type testcase =
      | EVAL of formula * bool

    let runner tc =
      match tc with
      | EVAL (f, ans) -> eval f = ans

    let string_of_tc tc =
      match tc with
      | EVAL (f, ans) -> (string_of_fomula f, string_of_bool (eval f), string_of_bool ans)

    let testcases =
      [ EVAL (TRUE, true)
      ; EVAL (FALSE, false)
      ; EVAL (NOT TRUE, false)
      ; EVAL (NOT FALSE, true)
      ; EVAL (ANDALSO (TRUE, TRUE), true)
      ; EVAL (ANDALSO (TRUE, FALSE), false)
      ; EVAL (ANDALSO (FALSE, TRUE), false)
      ; EVAL (ANDALSO (FALSE, FALSE), false)
      ; EVAL (ORELSE (TRUE, TRUE), true)
      ; EVAL (ORELSE (TRUE, FALSE), true)
      ; EVAL (ORELSE (FALSE, TRUE), true)
      ; EVAL (ORELSE (FALSE, FALSE), false)
      ; EVAL (IMPLY (TRUE, TRUE), true)
      ; EVAL (IMPLY (TRUE, FALSE), false)
      ; EVAL (IMPLY (FALSE, TRUE), true)
      ; EVAL (IMPLY (FALSE, FALSE), true)
      ; EVAL (LESS (NUM 1, NUM 2), true)
      ; EVAL (LESS (NUM 2, NUM 1), false)
      ; EVAL (LESS (NUM (-100), NUM (-200)), false)
      ; EVAL (LESS (NUM (-200), NUM (-100)), true)
      ; EVAL (LESS (NUM (-10000), NUM 10000), true)
      ; EVAL (LESS (NUM 10000, NUM (-10000)), false)
      ; EVAL (LESS (PLUS (NUM 1, NUM 2), NUM 3), false)
      ; EVAL (LESS (PLUS (NUM 1, NUM 2), NUM 4), true)
      ; EVAL (LESS (MINUS (NUM 10, NUM 5), NUM 5), false)
      ; EVAL (LESS (MINUS (NUM 10, NUM 5), NUM 6), true)
      ; EVAL (LESS (PLUS (NUM (-12345), NUM 23456), NUM 11111), false)
      ; EVAL (LESS (PLUS (NUM (-12345), NUM 23456), NUM 11112), true)
      ; EVAL (LESS (MINUS (NUM 12345, NUM 23456), NUM (-11111)), false)
      ; EVAL (LESS (MINUS (NUM 12345, NUM 23456), NUM (-11110)), true)
      ]
  end

open TestEx1
let _ = wrapper exnum testcases runner string_of_tc
{'fraction_non_alphanumeric': 0.15885124523221897, 'fraction_numerical': 0.05743773838905093, 'mean_word_length': 2.5721153846153846, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4956810', 'n_tokens_mistral': 1943, 'n_tokens_neox': 1726, 'n_words': 590}