-
Notifications
You must be signed in to change notification settings - Fork 7
/
rtb_test.go
49 lines (40 loc) · 1.17 KB
/
rtb_test.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
package rtb
import (
"testing"
)
// TestCpmToMicroCents ensures that we are converting from CPM to MicroCents correctly.
func TestCpmToMicroCents(t *testing.T) {
cpm := 0.32
expected := int64(32000000)
actual := CpmToMicroCents(cpm)
if expected != actual {
t.Fail()
}
}
// TestMicroCentsToCpm ensures that we are converting from MicroCents to CPM correctly.
func TestMicroCentsToCpm(t *testing.T) {
microcents := int64(32000000)
expected := 0.32
actual := MicroCentsToCpm(microcents)
if expected != actual {
t.Fail()
}
}
// TestMicroCentsToCpmRounding ensures that we are converting from MicroCents to CPM correctly, considering rounding error may occur if incorrectly calculated.
func TestMicroCentsToCpmRounding(t *testing.T) {
microcents := int64(32100000)
expected := 0.321
actual := MicroCentsToCpm(microcents)
if expected != actual {
t.Fail()
}
}
// TestMicroCentsPerImpression ensures that we are properly calculating the number of micro cents to subtract per impression
func TestMicroCentsPerImpression(t *testing.T) {
microcents := int64(32000)
expected := int64(32)
actual := MicroCentsPerImpression(microcents)
if expected != actual {
t.Fail()
}
}