-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
72 lines (63 loc) · 3.59 KB
/
index.html
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
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8" />
<title>Abstract Unit Testing Simulator</title>
<script src="libs/jquery.min.js"></script>
<script src="libs/jquery.autosize-min.js"></script>
<script src="src/mather.js"></script>
<script src="src/index.js"></script>
<link rel="stylesheet" type="text/css" href="src/style.css"></link>
<link rel="stylesheet" type="text/css" href="libs/bootstrap/css/bootstrap.min.css"></link>
</head>
<body>
<h1>Abstract Unit Testing Simulator</h1>
<p>
Your co-worker has implemented a math parser, but doesn't think he needs to test it. You, of course, know that code <i>must always</i> be unit tested! Otherwise, when someone goes to "improve" it, they might not notice when they break something.
</p>
<p>
The parser can perform +,-,/, and *, and supports paranthesis. It's easy enough to feed garbage input to the system, and all bets are off if you do. You're only interested in ensuring that valid inputs get back valid results. However, it should handle something like <code>1.5+3/2*(9-2*8/(-2)+9)-6/24</code> without a problem.
</p>
<p>
Write a series of expressions -- one per line -- of the form <code>[expression] = [value]</code>, such as <code>1.5+3/2*(9-2*8/(-2)+9)-6/24 = 40.25</code>
to test against the parser. Initially, the parser should work exactly as expected. Hitting the "Improve" button will cause something to break, though!
</p>
<p><b>
Try to write a series of equations that will allow you to notice when something has broken, and identitify exactly what part of the parser has broken. Try to be as precise as possible, so your co-workers can spend less time trying to figure out what's wrong.
</b></p>
<div class="left-align">
<form id="input">
<textarea name="input" id="input-field">
This is a good unit test:
1+1 = 2
Write more equations like these to reduce what's wrong to simpler problems
This is a good integration test, but not a very helpful unit test:
1.5+3/2*(9-2*8/(-2)+9)-6/24 = 40.25
Writing more of these won't help
This is a garbage input:
2+3
There needs to be an equals sign asserting something for the parser to read the line
</textarea><br>
<button type="submit">Test</button>
<button id="randomize">"Improve"</button>
</form>
</div>
<div class="right-align">
<div id="output">
</div>
</div>
<div style="clear:both">
<p>
When you're comfortable with your ability to determine what's wrong, you can <a href="https://github.com/SteamedPears/live-debug/archive/clean-tests.zip">download</a> the source of this application and try to write actual unit tests. We've already gone ahead and taken care of all the messy stuff, you just need to add your tests to /tests/test.js. Then if you open up /tests/index.html in your browser, they should run!
</p>
<p>
These unit tests are written in <a href="http://qunitjs.com/">QUnit</a>, which is javascript specific, but most unit testing frameworks are basically the same:
<ul>
<li>Provide a statement</li>
<li>Make an assertion of what the result should be</li>
</ul>
It's exactly what you've been doing here, just a bit more formal.
</p>
</div>
</body>
</html>