summaryrefslogtreecommitdiffhomepage
path: root/types/bools/bools_test.go
blob: 67faf3bcc92d829f2de152566327aaa59a67111c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Copyright (c) Tailscale Inc & AUTHORS
// SPDX-License-Identifier: BSD-3-Clause

package bools

import "testing"

func TestInt(t *testing.T) {
	if got := Int(true); got != 1 {
		t.Errorf("Int(true) = %v, want 1", got)
	}
	if got := Int(false); got != 0 {
		t.Errorf("Int(false) = %v, want 0", got)
	}
}

func TestCompare(t *testing.T) {
	if got := Compare(false, false); got != 0 {
		t.Errorf("Compare(false, false) = %v, want 0", got)
	}
	if got := Compare(false, true); got != -1 {
		t.Errorf("Compare(false, true) = %v, want -1", got)
	}
	if got := Compare(true, false); got != +1 {
		t.Errorf("Compare(true, false) = %v, want +1", got)
	}
	if got := Compare(true, true); got != 0 {
		t.Errorf("Compare(true, true) = %v, want 0", got)
	}
}

func TestIfElse(t *testing.T) {
	if got := IfElse(true, 0, 1); got != 0 {
		t.Errorf("IfElse(true, 0, 1) = %v, want 0", got)
	}
	if got := IfElse(false, 0, 1); got != 1 {
		t.Errorf("IfElse(false, 0, 1) = %v, want 1", got)
	}
}