From 91ac2c58fa36e5cc6bd26892567c5e48332659ef Mon Sep 17 00:00:00 2001 From: Tatsuhiko Kubo Date: Sat, 14 Nov 2015 11:38:26 +0900 Subject: [PATCH] fixed test failure. When CPU is 1 core, expected value (int(0.5 * float32(maxCPU))) is zero. But runtime.GOMAXPROCS(-1) returns always 1. --- main_test.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/main_test.go b/main_test.go index 4e61afa8..31167316 100644 --- a/main_test.go +++ b/main_test.go @@ -8,6 +8,10 @@ import ( func TestSetCPU(t *testing.T) { currentCPU := runtime.GOMAXPROCS(-1) maxCPU := runtime.NumCPU() + halfCPU := int(0.5 * float32(maxCPU)) + if halfCPU < 1 { + halfCPU = 1 + } for i, test := range []struct { input string output int @@ -17,7 +21,7 @@ func TestSetCPU(t *testing.T) { {"-1", currentCPU, true}, {"0", currentCPU, true}, {"100%", maxCPU, false}, - {"50%", int(0.5 * float32(maxCPU)), false}, + {"50%", halfCPU, false}, {"110%", currentCPU, true}, {"-10%", currentCPU, true}, {"invalid input", currentCPU, true},