bools_test.go 979 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. // Copyright (c) Tailscale Inc & contributors
  2. // SPDX-License-Identifier: BSD-3-Clause
  3. package bools
  4. import "testing"
  5. func TestInt(t *testing.T) {
  6. if got := Int(true); got != 1 {
  7. t.Errorf("Int(true) = %v, want 1", got)
  8. }
  9. if got := Int(false); got != 0 {
  10. t.Errorf("Int(false) = %v, want 0", got)
  11. }
  12. }
  13. func TestCompare(t *testing.T) {
  14. if got := Compare(false, false); got != 0 {
  15. t.Errorf("Compare(false, false) = %v, want 0", got)
  16. }
  17. if got := Compare(false, true); got != -1 {
  18. t.Errorf("Compare(false, true) = %v, want -1", got)
  19. }
  20. if got := Compare(true, false); got != +1 {
  21. t.Errorf("Compare(true, false) = %v, want +1", got)
  22. }
  23. if got := Compare(true, true); got != 0 {
  24. t.Errorf("Compare(true, true) = %v, want 0", got)
  25. }
  26. }
  27. func TestIfElse(t *testing.T) {
  28. if got := IfElse(true, 0, 1); got != 0 {
  29. t.Errorf("IfElse(true, 0, 1) = %v, want 0", got)
  30. }
  31. if got := IfElse(false, 0, 1); got != 1 {
  32. t.Errorf("IfElse(false, 0, 1) = %v, want 1", got)
  33. }
  34. }