2012-02-16 21:50:37 -07:00
|
|
|
// run
|
2008-06-06 15:27:34 -06:00
|
|
|
|
|
|
|
// 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.
|
|
|
|
|
2012-02-23 22:24:24 -07:00
|
|
|
// Test basic operations on bool.
|
|
|
|
|
2008-06-06 15:27:34 -06:00
|
|
|
package main
|
|
|
|
|
2009-12-10 13:53:23 -07:00
|
|
|
type s struct {
|
2008-06-06 15:27:34 -06:00
|
|
|
a bool;
|
|
|
|
b bool;
|
|
|
|
}
|
|
|
|
|
|
|
|
func
|
2009-12-10 13:53:23 -07:00
|
|
|
main() {
|
2008-06-06 15:27:34 -06:00
|
|
|
var a,b bool;
|
|
|
|
|
|
|
|
a = true;
|
|
|
|
b = false;
|
|
|
|
|
2008-08-11 23:07:49 -06:00
|
|
|
if !a { panic(1); }
|
|
|
|
if b { panic(2); }
|
|
|
|
if !!!a { panic(3); }
|
|
|
|
if !!b { panic(4); }
|
2008-06-06 15:27:34 -06:00
|
|
|
|
|
|
|
a = !b;
|
2008-08-11 23:07:49 -06:00
|
|
|
if !a { panic(5); }
|
|
|
|
if !!!a { panic(6); }
|
2008-06-06 15:27:34 -06:00
|
|
|
|
|
|
|
var x *s;
|
2009-01-06 16:19:02 -07:00
|
|
|
x = new(s);
|
2008-06-06 15:27:34 -06:00
|
|
|
x.a = true;
|
|
|
|
x.b = false;
|
|
|
|
|
2008-08-11 23:07:49 -06:00
|
|
|
if !x.a { panic(7); }
|
|
|
|
if x.b { panic(8); }
|
|
|
|
if !!!x.a { panic(9); }
|
|
|
|
if !!x.b { panic(10); }
|
2008-06-06 15:27:34 -06:00
|
|
|
|
|
|
|
x.a = !x.b;
|
2008-08-11 23:07:49 -06:00
|
|
|
if !x.a { panic(11); }
|
|
|
|
if !!!x.a { panic(12); }
|
2008-06-06 15:27:34 -06:00
|
|
|
|
|
|
|
/*
|
|
|
|
* test &&
|
|
|
|
*/
|
|
|
|
a = true;
|
|
|
|
b = true;
|
2008-08-11 23:07:49 -06:00
|
|
|
if !(a && b) { panic(21); }
|
|
|
|
if a && !b { panic(22); }
|
|
|
|
if !a && b { panic(23); }
|
|
|
|
if !a && !b { panic(24); }
|
2008-06-06 15:27:34 -06:00
|
|
|
|
|
|
|
a = false;
|
|
|
|
b = true;
|
2008-08-11 23:07:49 -06:00
|
|
|
if !(!a && b) { panic(31); }
|
|
|
|
if !a && !b { panic(32); }
|
|
|
|
if a && b { panic(33); }
|
|
|
|
if a && !b { panic(34); }
|
2008-06-06 15:27:34 -06:00
|
|
|
|
|
|
|
a = true;
|
|
|
|
b = false;
|
2008-08-11 23:07:49 -06:00
|
|
|
if !(a && !b) { panic(41); }
|
|
|
|
if a && b { panic(41); }
|
|
|
|
if !a && !b { panic(41); }
|
|
|
|
if !a && b { panic(44); }
|
2008-06-06 15:27:34 -06:00
|
|
|
|
|
|
|
a = false;
|
|
|
|
b = false;
|
2008-08-11 23:07:49 -06:00
|
|
|
if !(!a && !b) { panic(51); }
|
|
|
|
if !a && b { panic(52); }
|
|
|
|
if a && !b { panic(53); }
|
|
|
|
if a && b { panic(54); }
|
2008-06-06 15:27:34 -06:00
|
|
|
|
|
|
|
/*
|
|
|
|
* test ||
|
|
|
|
*/
|
|
|
|
a = true;
|
|
|
|
b = true;
|
2008-08-11 23:07:49 -06:00
|
|
|
if !(a || b) { panic(61); }
|
|
|
|
if !(a || !b) { panic(62); }
|
|
|
|
if !(!a || b) { panic(63); }
|
|
|
|
if !a || !b { panic(64); }
|
2008-06-06 15:27:34 -06:00
|
|
|
|
|
|
|
a = false;
|
|
|
|
b = true;
|
2008-08-11 23:07:49 -06:00
|
|
|
if !(!a || b) { panic(71); }
|
|
|
|
if !(!a || !b) { panic(72); }
|
|
|
|
if !(a || b) { panic(73); }
|
|
|
|
if a || !b { panic(74); }
|
2008-06-06 15:27:34 -06:00
|
|
|
|
|
|
|
a = true;
|
|
|
|
b = false;
|
2008-08-11 23:07:49 -06:00
|
|
|
if !(a || !b) { panic(81); }
|
|
|
|
if !(a || b) { panic(82); }
|
|
|
|
if !(!a || !b) { panic(83); }
|
|
|
|
if !a || b { panic(84); }
|
2008-06-06 15:27:34 -06:00
|
|
|
|
|
|
|
a = false;
|
|
|
|
b = false;
|
2008-08-11 23:07:49 -06:00
|
|
|
if !(!a || !b) { panic(91); }
|
|
|
|
if !(!a || b) { panic(92); }
|
|
|
|
if !(a || !b) { panic(93); }
|
|
|
|
if a || b { panic(94); }
|
2008-06-06 15:27:34 -06:00
|
|
|
}
|