simpbool.go 1.76 KB
Newer Older
Rob Pike's avatar
Rob Pike committed
1 2 3 4 5 6 7 8
// $G $D/$F.go && $L $F.$A && ./$A.out

// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package main

9
type s struct {
Rob Pike's avatar
Rob Pike committed
10 11 12 13 14
	a	bool;
	b	bool;
}

func
15
main() {
Rob Pike's avatar
Rob Pike committed
16 17 18 19 20
	var a,b bool;

	a = true;
	b = false;

Rob Pike's avatar
Rob Pike committed
21 22 23 24
	if !a { panic(1); }
	if b { panic(2); }
	if !!!a { panic(3); }
	if !!b { panic(4); }
Rob Pike's avatar
Rob Pike committed
25 26

	a = !b;
Rob Pike's avatar
Rob Pike committed
27 28
	if !a { panic(5); }
	if !!!a { panic(6); }
Rob Pike's avatar
Rob Pike committed
29 30

	var x *s;
Russ Cox's avatar
Russ Cox committed
31
	x = new(s);
Rob Pike's avatar
Rob Pike committed
32 33 34
	x.a = true;
	x.b = false;

Rob Pike's avatar
Rob Pike committed
35 36 37 38
	if !x.a { panic(7); }
	if x.b { panic(8); }
	if !!!x.a { panic(9); }
	if !!x.b { panic(10); }
Rob Pike's avatar
Rob Pike committed
39 40

	x.a = !x.b;
Rob Pike's avatar
Rob Pike committed
41 42
	if !x.a { panic(11); }
	if !!!x.a { panic(12); }
Rob Pike's avatar
Rob Pike committed
43 44 45 46 47 48

	/*
	 * test &&
	 */
	a = true;
	b = true;
Rob Pike's avatar
Rob Pike committed
49 50 51 52
	if !(a && b) { panic(21); }
	if a && !b { panic(22); }
	if !a && b { panic(23); }
	if !a && !b { panic(24); }
Rob Pike's avatar
Rob Pike committed
53 54 55

	a = false;
	b = true;
Rob Pike's avatar
Rob Pike committed
56 57 58 59
	if !(!a && b) { panic(31); }
	if !a && !b { panic(32); }
	if a && b { panic(33); }
	if a && !b { panic(34); }
Rob Pike's avatar
Rob Pike committed
60 61 62

	a = true;
	b = false;
Rob Pike's avatar
Rob Pike committed
63 64 65 66
	if !(a && !b) { panic(41); }
	if a && b { panic(41); }
	if !a && !b { panic(41); }
	if !a && b { panic(44); }
Rob Pike's avatar
Rob Pike committed
67 68 69

	a = false;
	b = false;
Rob Pike's avatar
Rob Pike committed
70 71 72 73
	if !(!a && !b) { panic(51); }
	if !a && b { panic(52); }
	if a && !b { panic(53); }
	if a && b { panic(54); }
Rob Pike's avatar
Rob Pike committed
74 75 76 77 78 79

	/*
	 * test ||
	 */
	a = true;
	b = true;
Rob Pike's avatar
Rob Pike committed
80 81 82 83
	if !(a || b) { panic(61); }
	if !(a || !b) { panic(62); }
	if !(!a || b) { panic(63); }
	if !a || !b { panic(64); }
Rob Pike's avatar
Rob Pike committed
84 85 86

	a = false;
	b = true;
Rob Pike's avatar
Rob Pike committed
87 88 89 90
	if !(!a || b) { panic(71); }
	if !(!a || !b) { panic(72); }
	if !(a || b) { panic(73); }
	if a || !b { panic(74); }
Rob Pike's avatar
Rob Pike committed
91 92 93

	a = true;
	b = false;
Rob Pike's avatar
Rob Pike committed
94 95 96 97
	if !(a || !b) { panic(81); }
	if !(a || b) { panic(82); }
	if !(!a || !b) { panic(83); }
	if !a || b { panic(84); }
Rob Pike's avatar
Rob Pike committed
98 99 100

	a = false;
	b = false;
Rob Pike's avatar
Rob Pike committed
101 102 103 104
	if !(!a || !b) { panic(91); }
	if !(!a || b) { panic(92); }
	if !(a || !b) { panic(93); }
	if a || b { panic(94); }
Rob Pike's avatar
Rob Pike committed
105
}