mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Merge pull request #230 from BillKeenan/addBargraphTest
Add bargraph test
This commit is contained in:
commit
5caff0c617
@ -9,4 +9,4 @@ before_install:
|
|||||||
- export TRAVIS_BUILD_DIR=$HOME/gopath/src/github.com/senorprogrammer/wtf
|
- export TRAVIS_BUILD_DIR=$HOME/gopath/src/github.com/senorprogrammer/wtf
|
||||||
- cd $HOME/gopath/src/github.com/senorprogrammer/wtf
|
- cd $HOME/gopath/src/github.com/senorprogrammer/wtf
|
||||||
|
|
||||||
script: go get ./... && go get github.com/go-test/deep && go test -v github.com/senorprogrammer/wtf/wtf_tests
|
script: go get ./... && go get github.com/go-test/deep && go test -v github.com/senorprogrammer/wtf/wtf_tests/...
|
||||||
|
@ -14,9 +14,9 @@ wtf:
|
|||||||
graphIcon: "💀"
|
graphIcon: "💀"
|
||||||
graphStars: 25
|
graphStars: 25
|
||||||
position:
|
position:
|
||||||
top: 3
|
top: 2
|
||||||
left: 0
|
left: 0
|
||||||
height: 1
|
height: 2
|
||||||
width: 2
|
width: 2
|
||||||
refreshInterval: 30
|
refreshInterval: 30
|
||||||
updateInterval: 15
|
updateInterval: 15
|
||||||
|
@ -103,6 +103,12 @@ func (widget *BarGraph) addView() {
|
|||||||
// time should be passed as a int64
|
// time should be passed as a int64
|
||||||
func (widget *BarGraph) BuildBars(data [][2]int64) {
|
func (widget *BarGraph) BuildBars(data [][2]int64) {
|
||||||
|
|
||||||
|
widget.View.SetText(BuildStars(data, widget.maxStars, widget.starChar))
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//BuildStars build the string to display
|
||||||
|
func BuildStars(data [][2]int64, maxStars int, starChar string) string {
|
||||||
var buffer bytes.Buffer
|
var buffer bytes.Buffer
|
||||||
|
|
||||||
//counter to inintialize min value
|
//counter to inintialize min value
|
||||||
@ -138,7 +144,7 @@ func (widget *BarGraph) BuildBars(data [][2]int64) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// each number = how many stars?
|
// each number = how many stars?
|
||||||
var starRatio = float64(widget.maxStars) / float64((maxValue - minValue))
|
var starRatio = float64(maxStars) / float64((maxValue - minValue))
|
||||||
|
|
||||||
//build the stars
|
//build the stars
|
||||||
for i := range data {
|
for i := range data {
|
||||||
@ -151,7 +157,7 @@ func (widget *BarGraph) BuildBars(data [][2]int64) {
|
|||||||
starCount = 1
|
starCount = 1
|
||||||
}
|
}
|
||||||
//build the actual string
|
//build the actual string
|
||||||
var stars = strings.Repeat(widget.starChar, starCount)
|
var stars = strings.Repeat(starChar, starCount)
|
||||||
|
|
||||||
//parse the time
|
//parse the time
|
||||||
var t = time.Unix(int64(data[i][1]/1000), 0)
|
var t = time.Unix(int64(data[i][1]/1000), 0)
|
||||||
@ -160,8 +166,7 @@ func (widget *BarGraph) BuildBars(data [][2]int64) {
|
|||||||
buffer.WriteString(fmt.Sprintf("%s -\t [red]%s[white] - (%d)\n", t.Format("Jan 02, 2006"), stars, val))
|
buffer.WriteString(fmt.Sprintf("%s -\t [red]%s[white] - (%d)\n", t.Format("Jan 02, 2006"), stars, val))
|
||||||
}
|
}
|
||||||
|
|
||||||
widget.View.SetText(buffer.String())
|
return buffer.String()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------- Exported Functions -------------------- */
|
/* -------------------- Exported Functions -------------------- */
|
||||||
|
33
wtf_tests/bargraph/bargraph_test.go
Normal file
33
wtf_tests/bargraph/bargraph_test.go
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
package bargraphtests
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
. "github.com/senorprogrammer/wtf/wtf"
|
||||||
|
. "github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
// MakeData - Create sample data
|
||||||
|
func makeData() [][2]int64 {
|
||||||
|
|
||||||
|
//this could come from config
|
||||||
|
const lineCount = 2
|
||||||
|
var stats [lineCount][2]int64
|
||||||
|
|
||||||
|
stats[0][1] = 1530122942
|
||||||
|
stats[0][0] = 100
|
||||||
|
|
||||||
|
stats[1][1] = 1530132942
|
||||||
|
stats[1][0] = 210
|
||||||
|
|
||||||
|
return stats[:]
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//TestOutput of the bargraph make string (BuildStars) function
|
||||||
|
func TestOutput(t *testing.T) {
|
||||||
|
|
||||||
|
result := BuildStars(makeData(), 20, "*")
|
||||||
|
|
||||||
|
Equal(t, result, "Jan 18, 1970 -\t [red]*[white] - (100)\nJan 18, 1970 -\t [red]********************[white] - (210)\n")
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user