This repository has been archived on 2015-04-29. You can view files and clone it, but cannot push or open issues or pull requests.
jsh/free/main_test.go
Fredric Silberberg f21df51bd2 Added the PATH searching algorithm we talked about at the last meeting with Ciaraldi. It will find the location of our program
and search the PATH for that location. If found, it will search all remaining elements for the requested program. If the location
is not found on the PATH, then it will search the entire PATH for the requested program. If found, it returns the absolute path
to the program. If not, err.
2014-09-24 23:32:11 -04:00

77 lines
1.8 KiB
Go

package main
import (
"jsh"
"reflect"
"testing"
)
func testUnitError(expected jsh.Unit, t *testing.T) {
actual, error := ConvertUnit(expected.ToString())
if error != nil {
t.Error(error)
}
if actual != expected {
t.Errorf("Conversion error: expected %s, received %s", expected.ToString(), actual.ToString())
}
}
func TestConvertUnit(t *testing.T) {
// Good unit conversions
testUnitError(jsh.B, t)
testUnitError(jsh.KB, t)
testUnitError(jsh.MB, t)
testUnitError(jsh.GB, t)
testUnitError(jsh.TB, t)
// Test the empty unit, because this exists on some systems
actual, error := ConvertUnit("")
if error != nil {
t.Error(error)
}
if actual != jsh.B {
t.Errorf("Conversion error: expected %s, received %s", jsh.B.ToString(), actual.ToString())
}
}
func TestConvertBadUnit(t *testing.T) {
// Testing a bad unit conversion
actual, error := ConvertUnit("pB")
if error == nil {
t.Error("Expected an error for unit pB, received value of ", actual)
}
}
func TestParseGoodLine(t *testing.T) {
goodLine := "MemTotal: 16370344 kB"
expectedStat := jsh.MemStat{16370344, jsh.KB}
expectedKey := "MemTotal"
key, stat, err := ParseLine(goodLine)
if err != nil {
t.Error(err)
}
if key != expectedKey {
t.Errorf("Expected key %s, got key %s", expectedKey, key)
}
if !reflect.DeepEqual(expectedStat, stat) {
t.Error("Expected stat ", expectedStat, " got ", stat)
}
}
func TestParseBadUnit(t *testing.T) {
badLine := "MemTotal: 16370344 pB"
key, stat, err := ParseLine(badLine)
if err == nil {
t.Error("Expected error, received key ", key, " and stat ", stat)
}
}
func TestParseBadNumber(t *testing.T) {
badLine := "MemTotal: 1637034p pB"
key, stat, err := ParseLine(badLine)
if err == nil {
t.Error("Expected error, received key ", key, " and stat ", stat)
}
}