-
Notifications
You must be signed in to change notification settings - Fork 1
/
testMealCalculator.html
109 lines (84 loc) · 4.24 KB
/
testMealCalculator.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
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
<html>
<head>
<title>Meal Calculator</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js"></script>
<script type="text/javascript" src="mac_menu.js"></script>
<script type="text/javascript" src="mos_menu.js"></script>
<script type="text/javascript" src="meal_calculator.js"></script>
<link rel="stylesheet" href="testsuite.css" />
<script type="text/javascript">
$(document).ready(function(){
var lifeCycle = {
setup: function(){
mealCalculator.setMenu(macMenu.getMenu());
}
};
module("internals", lifeCycle);
test("get valid foods", function(){
var input = "雙層芝士孖堡 ,中薯條,中可樂, 雞翼";
var output = mealCalculator.getValidFoods(input);
//if(console && console.log) console.log(output.join(','));
equals(output.join(','), '雙層芝士孖堡,中薯條,中可樂');
});
test("match meal food", function(){
var input = "雙層芝士孖堡,中薯條,中可樂,至尊漢堡".split(',');
var result = mealCalculator.matchMealFood(input, '至尊漢堡套餐');
equals(result, true);
result = mealCalculator.matchMealFood(input, '雙層芝士孖堡套餐');
equals(result, true);
result = mealCalculator.matchMealFood('中薯條,中可樂'.split(','), '雙層芝士孖堡套餐');
equals(result, false);
});
test("get money saved by meal", function(){
equals(mealCalculator.getMoneySavedByMeal('雙層芝士孖堡套餐'), 6);
equals(mealCalculator.getMoneySavedByMeal('至尊漢堡套餐'), 7.5);
});
test("get worthiest meal", function(){
var input = "雙層芝士孖堡,中薯條,中可樂,至尊漢堡".split(',');
var meal = mealCalculator.getWorthiestMeal(input);
//if(console && console.log) console.log(meal);
equals(meal, '至尊漢堡套餐');
});
test("substract meal food from items", function(){
var input = "雙層芝士孖堡,中薯條,中可樂,至尊漢堡".split(',');
var output = mealCalculator.subtractMealFoodFromItems(input, "至尊漢堡套餐");
//if(console && console.log) console.log(output.join(','));
equals(output.join(','), '雙層芝士孖堡');
});
test("get ordred meals", function(){
equals(mealCalculator.getOrderedMeals().join(','),'至尊漢堡套餐,雙層芝士孖堡套餐');
});
module("main test", lifeCycle);
test("main caculate", function(){
equals(mealCalculator.calculate("雙層芝士孖堡,中薯條,中可樂,至尊漢堡"), '至尊漢堡套餐,雙層芝士孖堡');
equals(mealCalculator.calculate("雙層芝士孖堡,中薯條,中可樂,中可樂"), '雙層芝士孖堡套餐,中可樂');
equals(mealCalculator.calculate("雙層芝士孖堡,中可樂,中可樂"), '雙層芝士孖堡,中可樂,中可樂');
equals(mealCalculator.calculate("雙層芝士孖堡,中薯條,中可樂,中薯條,中可樂,至尊漢堡"), '至尊漢堡套餐,雙層芝士孖堡套餐');
equals(mealCalculator.calculate("雙層芝士孖堡,雙層芝士孖堡,雙層芝士孖堡,中薯條,中可樂"), '雙層芝士孖堡套餐,雙層芝士孖堡,雙層芝士孖堡');
});
module("test mos menu");
test("search food", function(){
equals(mosMenu.searchFood({type:'drink'}).join(','),'摩斯紅茶,香磨咖啡,可口可樂(M),可口可樂(L),鮮奶咖啡,抺茶鮮奶');
equals(mosMenu.searchFood({type:'burger'}).join(','),'摩斯漢堡,摩斯芝士漢堡,照燒牛油果漢堡');
equals(mosMenu.searchFood({type:'side',combo:'A'}).join(','),'厚切薯條(S)');
equals(mosMenu.searchFood({type:'side',combo:'B'}).join(','),'蝶蝶蝦,摩斯脆雞');
});
test("get all meals", function(){
var meals = mosMenu.getAllMeals();
for(var m in meals){
console.log(m + ' -- ' + meals[m].foods.join(',') + " -- $" + meals[m].price);
}
ok(true,"view console.log");
});
});
</script>
</head>
<body>
<script type="text/javascript" src="testrunner.js"></script>
<h1>Test Meal Calculator</h1>
<h2 id="banner"></h2>
<h2 id="userAgent"></h2>
<ol id="tests"></ol>
<div id="main"></div>
</body>
</html>