-
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.
Merge pull request #3 from burrelle/test/refactor
Refactor to be able to unit test
- Loading branch information
Showing
2 changed files
with
71 additions
and
7 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,46 @@ | ||
package main | ||
|
||
import "testing" | ||
|
||
func TestReadArguments(t *testing.T) { | ||
t.Run("verify with correct parameters", func(t *testing.T) { | ||
want := int64(12) | ||
args := []string{"12", "12"} | ||
var load, percentage = readArguments(args) | ||
if load != want || percentage != want { | ||
t.Errorf("should have recieved a value back") | ||
} | ||
}) | ||
|
||
t.Run("verify with incorrect parameters", func(t *testing.T) { | ||
args := []string{"not-a-number", "not-a-number"} | ||
var load, percentage = readArguments(args) | ||
if load != 0 && percentage != 0 { | ||
t.Errorf("should have recieved zero") | ||
} | ||
}) | ||
} | ||
|
||
func TestCaluatePercentage(t *testing.T) { | ||
t.Run("calculates the percentage based on input", func(t *testing.T) { | ||
percentageLoad := int64(78) | ||
want := float64(0.78) | ||
var percentage = calcuatePercentage(percentageLoad) | ||
if want != percentage { | ||
t.Errorf("should have recieved a value back") | ||
} | ||
}) | ||
} | ||
|
||
func TestCalculateCPUCount(t *testing.T) { | ||
t.Run("calculates the percentage based on input", func(t *testing.T) { | ||
percentageLoad := float64(0.78) | ||
CPU := 4 | ||
want := float64(3.12) | ||
var percentage = calcuateCPUCount(percentageLoad, CPU) | ||
print(percentage) | ||
if want != percentage { | ||
t.Errorf("should have recieved a value back") | ||
} | ||
}) | ||
} |