-
-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathtwo_fer.ex
148 lines (120 loc) · 2.8 KB
/
two_fer.ex
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
defmodule ElixirAnalyzer.TestSuite.TwoFer do
@moduledoc """
This is an exercise analyzer extension module for the exercise TwoFer
Written by: Tim Austin (@neenjaw) [email protected]
"""
alias ElixirAnalyzer.Constants
use ElixirAnalyzer.ExerciseTest
#
# Two-fer feature tests
#
feature "has spec" do
# status :skip
find :all
type :actionable
comment Constants.solution_use_specification()
form do
@spec _ignore
end
end
feature "has wrong spec" do
# status :skip
find :all
type :actionable
suppress_if "has spec", :fail
comment Constants.two_fer_wrong_specification()
form do
@spec two_fer(String.t()) :: String.t()
end
end
feature "has default parameter" do
# status :skip
find :any
type :actionable
comment Constants.two_fer_use_default_parameter()
# function header
form do
def two_fer(_ignore \\ "you")
end
# function without a guard and with a do block
form do
def two_fer(_ignore \\ "you") do
_ignore
end
end
# function with do block
form do
def two_fer(_ignore \\ "you") when _ignore do
_ignore
end
end
end
feature "uses function header" do
# status :skip
find :none
type :actionable
comment Constants.two_fer_use_of_function_header()
form do
def two_fer(_ignore \\ "you")
end
end
feature "uses guards" do
# status :skip
find :any
type :actionable
comment Constants.two_fer_use_guards()
form do
is_binary(_ignore)
end
form do
is_bitstring(_ignore)
end
end
feature "uses function level guard" do
# status :skip
find :any
type :actionable
suppress_if "uses guards", :fail
comment Constants.two_fer_use_function_level_guard()
form do
def two_fer(_ignore \\ "you") when is_binary(_ignore), _ignore
end
form do
def two_fer(_ignore) when is_binary(_ignore), _ignore
end
form do
def two_fer(_ignore \\ "you") when is_bitstring(_ignore), _ignore
end
form do
def two_fer(_ignore) when is_bitstring(_ignore), _ignore
end
end
feature "uses auxiliary functions" do
# status :skip
find :none
type :actionable
comment Constants.two_fer_use_of_aux_functions()
form do
defp _ignore(_ignore), do: _ignore
end
end
feature "uses string interpolation" do
# status :skip
find :any
type :actionable
comment Constants.two_fer_use_string_interpolation()
form do
"One for #{_ignore}, one for me."
end
end
feature "first level @moduledoc recommended" do
# status :skip
find :all
type :informative
comment Constants.solution_use_moduledoc()
depth 1
form do
@moduledoc _ignore
end
end
end