generated from bobbicodes/ctrain
-
Notifications
You must be signed in to change notification settings - Fork 5
/
tests.clj
41 lines (36 loc) · 1.44 KB
/
tests.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
(ns forebb_test
(:require [clojure.java.io :as io]
[clojure.set]
[clojure.string :as str]
[clojure.test :as t :refer [deftest is testing]]))
(declare problems)
(load-file "problems.clj")
(def answer-files
(->> (io/file "answers")
(.listFiles)
(filter #(re-matches #".*\d+" (.getPath %)))))
(defn restricted-fns [ans res-fns]
(let [ans-sym (into #{} (filter symbol? (flatten (read-string ans))))
res-sym (into #{} (map symbol res-fns))]
(clojure.set/intersection ans-sym res-sym)))
(deftest forebb-test
(doseq [^java.io.File answer-file answer-files]
(let [name (.getName answer-file)
n (Integer/parseInt name)
ans (slurp answer-file)
problem (some (fn [{id :_id :as p}]
(when (= id n)
p))
problems)
tests (:tests problem)
restricted (get problem :restricted [])
replaced (mapv #(str/replace % "__" ans) tests)
bad-fns (restricted-fns (first replaced) restricted)]
(testing (str "Running tests for the problem " n)
(assert (empty? bad-fns)
(str "Ops, you are using restricted functions: " bad-fns))
(doseq [test replaced]
(is (eval (read-string test))))))))
(let [report (t/run-tests)]
(System/exit (+ (:fail report)
(:error report))))