forked from instructure/canvas-lms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuizFormulaSolutionSpec.coffee
More file actions
64 lines (50 loc) · 1.83 KB
/
Copy pathQuizFormulaSolutionSpec.coffee
File metadata and controls
64 lines (50 loc) · 1.83 KB
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
define ['quiz_formula_solution'], (QuizFormulaSolution)->
QUnit.module "QuizForumlaSolution",
setup: ->
teardown: ->
test 'constructor: property setting', ->
solution = new QuizFormulaSolution("= 0")
equal(solution.result, "= 0")
checkValue = (input, expected)->
solution = new QuizFormulaSolution(input)
equal(solution.rawValue(), expected)
checkText = (input, expected)->
solution = new QuizFormulaSolution(input)
equal(solution.rawText(), expected)
test 'can parse out raw values', ->
checkValue("= 0", 0)
checkValue("= 2.5", 2.5)
checkValue("= 17", 17)
checkValue("= -25.12", -25.12)
checkValue("= 1000000000.45", 1000000000.45)
test 'parsing out text of value', ->
checkText("= 0", "0")
checkText("= 2.5", "2.5")
checkText("= 17", "17")
checkText("= -25.12", "-25.12")
checkText("= 1000000000.45", "1000000000.45")
test "parses bad numbers effectively", ->
solution = new QuizFormulaSolution("= NotReallyValuable")
ok(isNaN(solution.rawValue()))
solution = new QuizFormulaSolution(null)
ok(isNaN(solution.rawValue()))
solution = new QuizFormulaSolution(undefined)
ok(isNaN(solution.rawValue()))
QUnit.module "QuizForumlaSolution#isValid",
setup: ->
teardown: ->
checkSolutionValidity = (input, validity)->
solution = new QuizFormulaSolution(input)
equal(solution.isValid(), validity)
test 'false without starting with =', ->
checkSolutionValidity("0", false)
test 'false if NaN', ->
checkSolutionValidity("= NaN", false)
test 'false if Infinity', ->
checkSolutionValidity("= Infinity", false)
test 'false if not a number', ->
checkSolutionValidity("= ABCDE", false)
test 'true for valid number', ->
checkSolutionValidity("= 2.5", true)
test 'true for 0', ->
checkSolutionValidity("= 0", true)