summaryrefslogtreecommitdiff
path: root/password-philosophy/pp-test.scm
blob: f1b9c640b3f9854d04e73a117572a8adec5bec52 (plain)
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
;; -*- compile-command: "guile -L . pp-test.scm"; -*-
(use-modules (srfi srfi-64)
	     (pp))

(test-begin "harness")


(test-equal "no occurrences"
  0
  (count-occurrences "" #\f))

(test-equal "one occurrences"
  1
  (count-occurrences "f" #\f))

(test-equal "one mixed occurrences"
  1
  (count-occurrences "fc" #\c))

(test-equal "two mixed occurrences"
  2
  (count-occurrences "zzf9ct5f" #\f))

(test-assert "Single X"
  (valid-password-p1? "X" #\X '(1 . 1)))

(test-assert "Single X extra"
  (valid-password-p1? "the X marks the spot" #\X '(1 . 1)))

(test-assert "Double X allowed"
  (valid-password-p1? "X lots of bad things use the logo of just an X" #\X '(1 . 2)))

(test-assert "Double X forced"
  (valid-password-p1? "X lots of bad things use the logo of just an X" #\X '(2 . 2)))

(test-assert "Double X failed"
  (not (valid-password-p1? "lots of bad things use the logo of just an X" #\X '(2 . 2))))

(test-equal "Parse line 1"
  '("abcde" #\a (1 . 3))
  (parse-line "1-3 a: abcde"))

(test-equal "Parse line 2"
  '("ccccccccc" #\c (2 . 9))
  (parse-line "2-9 c: ccccccccc"))

(test-equal "Count valid 0"
  0
  (pp "1-3 a: bcde
1-3 b: cdefg
2-9 c: cccccccccc" #t))

(test-equal "Count valid 1"
  1
  (pp "1-3 a: abcde
1-3 b: cdefg
2-9 c: cccccccccc" #t))

(test-equal "Count valid 2"
  2
  (pp "1-3 a: abcde
1-3 b: cdefg
2-9 c: ccccccccc" #t))

(test-equal "Count valid 3"
  3
  (pp "1-3 a: abcde
1-3 b: cdbfg
2-9 c: ccccccccc" #t))

(test-assert "First char matched"
  (valid-password-p2? ":)" #\) '(1 . 2)))

(test-assert "Neither chars matched"
  (not (valid-password-p2? ":(" #\) '(1 . 2))))

(test-assert "Example 1"
  (valid-password-p2? "abcde" #\a '(1 . 3)))

(test-assert "Example 2"
  (not (valid-password-p2? "cdefg" #\b '(1 . 3))))

(test-assert "Example 3"
  (not (valid-password-p2? "cccccccccc" #\a '(2 . 9))))


(test-end "harness")