diff options
author | Christopher Speller <crspeller@gmail.com> | 2016-05-12 23:56:07 -0400 |
---|---|---|
committer | Christopher Speller <crspeller@gmail.com> | 2016-05-12 23:56:07 -0400 |
commit | 38ee83e45b4de7edf89bf9f0ef629eb4c6ad0fa8 (patch) | |
tree | a4fde09672192b97d453ad605b030bd5a10c5a45 /vendor/github.com/disintegration/imaging/utils_test.go | |
parent | 84d2482ddbff9564c9ad75b2d30af66e3ddfd44d (diff) | |
download | chat-38ee83e45b4de7edf89bf9f0ef629eb4c6ad0fa8.tar.gz chat-38ee83e45b4de7edf89bf9f0ef629eb4c6ad0fa8.tar.bz2 chat-38ee83e45b4de7edf89bf9f0ef629eb4c6ad0fa8.zip |
Moving to glide
Diffstat (limited to 'vendor/github.com/disintegration/imaging/utils_test.go')
-rw-r--r-- | vendor/github.com/disintegration/imaging/utils_test.go | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/vendor/github.com/disintegration/imaging/utils_test.go b/vendor/github.com/disintegration/imaging/utils_test.go new file mode 100644 index 000000000..99aa8c82f --- /dev/null +++ b/vendor/github.com/disintegration/imaging/utils_test.go @@ -0,0 +1,81 @@ +package imaging + +import ( + "runtime" + "testing" +) + +func testParallelN(enabled bool, n, procs int) bool { + data := make([]bool, n) + before := runtime.GOMAXPROCS(0) + runtime.GOMAXPROCS(procs) + parallel(n, func(start, end int) { + for i := start; i < end; i++ { + data[i] = true + } + }) + for i := 0; i < n; i++ { + if data[i] != true { + return false + } + } + runtime.GOMAXPROCS(before) + return true +} + +func TestParallel(t *testing.T) { + for _, e := range []bool{true, false} { + for _, n := range []int{1, 10, 100, 1000} { + for _, p := range []int{1, 2, 4, 8, 16, 100} { + if testParallelN(e, n, p) != true { + t.Errorf("test [parallel %v %d %d] failed", e, n, p) + } + } + } + } +} + +func TestClamp(t *testing.T) { + td := []struct { + f float64 + u uint8 + }{ + {0, 0}, + {255, 255}, + {128, 128}, + {0.49, 0}, + {0.50, 1}, + {254.9, 255}, + {254.0, 254}, + {256, 255}, + {2500, 255}, + {-10, 0}, + {127.6, 128}, + } + + for _, d := range td { + if clamp(d.f) != d.u { + t.Errorf("test [clamp %v %v] failed: %v", d.f, d.u, clamp(d.f)) + } + } +} + +func TestClampint32(t *testing.T) { + td := []struct { + i int32 + u uint8 + }{ + {0, 0}, + {255, 255}, + {128, 128}, + {256, 255}, + {2500, 255}, + {-10, 0}, + } + + for _, d := range td { + if clampint32(d.i) != d.u { + t.Errorf("test [clampint32 %v %v] failed: %v", d.i, d.u, clampint32(d.i)) + } + } +} |