-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
113 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package ceb | ||
|
||
import "testing" | ||
|
||
const station = "fake-station" | ||
const co2 = "co2" | ||
const so2 = "so2" | ||
|
||
func TestStaleDetector(t *testing.T) { | ||
d := newDetector() | ||
|
||
for i := 0; i < staleMaxUpdates; i++ { | ||
if d.isStale(station, co2, 100) { | ||
t.Fatal("value should not be stale") | ||
} | ||
} | ||
|
||
if d.isStale(station, so2, 50) { | ||
t.Fatal("value uses other pollutant and should not be stale") | ||
} | ||
|
||
for i := 0; i < staleMaxUpdates*2; i++ { | ||
if d.isStale(station, so2, float64(i)) { | ||
t.Fatal("value is changing and should not be stale") | ||
} | ||
} | ||
|
||
if !d.isStale(station, co2, 100) { | ||
t.Fatal("value should be stale") | ||
} | ||
|
||
if d.isStale(station, co2, 42) { | ||
t.Fatal("value has changed and should not be stale") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters