-
Notifications
You must be signed in to change notification settings - Fork 16
/
doc.go
75 lines (75 loc) · 2.86 KB
/
doc.go
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
// Package score provides support for scoring tests.
//
// It is intended to be used in concert with the QuickFeed web service,
// which automates execution and scoring of student implemented assignments
// aimed to pass a given set of tests.
//
// QuickFeed computes the score according to the formulas below, providing
// a percentage score for a test or a group of tests. The Weight parameter can
// be used to give more or less weight to some Score objects (representing
// different test sets). For example, if TestA has Weight 2 and TestB has Weight 1,
// then passing TestA gives twice the score of passing TestB.
//
// QuickFeed computes the final score as follows:
// TotalWeight = sum(Weight)
// TaskScore[i] = Score[i] / MaxScore[i], gives {0 < TaskScore < 1}
// TaskWeight[i] = Weight[i] / TotalWeight
// TotalScore = sum(TaskScore[i]*TaskWeight[i]), gives {0 < TotalScore < 1}
//
// QuickFeed expects that tests are initialized in the init() method before test execution.
// This is done via the score.Add() method or the score.AddSub() method as shown below.
// Add() is used for regular tests, and AddSub() is used for subtests with individual scores.
//
// func init() {
// max, weight := len(fibonacciTests), 20
// score.Add(TestFibonacciMax, max, weight)
// score.Add(TestFibonacciMin, max, weight)
// for _, ft := range fibonacciTests {
// score.AddSub(TestFibonacciSubTest, subTestName("Max", ft.in), 1, 1)
// }
// for _, ft := range fibonacciTests {
// score.AddSub(TestFibonacciSubTest, subTestName("Min", ft.in), 1, 1)
// }
// }
//
// In addition, TestMain() should call score.PrintTestInfo() before running the tests
// to ensure that all tests are registered and will be picked up by QuickFeed.
//
// func TestMain(m *testing.M) {
// score.PrintTestInfo()
// os.Exit(m.Run())
// }
//
// To implement a test with scoring, you may use score.Max() to obtain a score object
// with Score equals to MaxScore, which may be decremented for each test failure.
// Note that sc.Print(t) should be called with a defer to ensure that it gets executed
// even if the test panics.
//
// func TestFibonacciMax(t *testing.T) {
// sc := score.Max()
// defer sc.Print(t)
// for _, ft := range fibonacciTests {
// out := fibonacci(ft.in)
// if out != ft.want {
// sc.Dec()
// }
// }
// }
//
// Similarly, it is also possible to use score.Min() to obtain a score object with
// Score equals to zero, which may be incremented for each test success.
//
// func TestFibonacciMin(t *testing.T) {
// sc := score.Min()
// defer sc.Print(t)
// for _, ft := range fibonacciTests {
// out := fibonacci(ft.in)
// if out == ft.want {
// sc.Inc()
// }
// }
// }
//
// Please see package score/testdata/sequence for other usage examples.
//
package score