From c33289238e8e48f8163a3a9f44979975ad068a6b Mon Sep 17 00:00:00 2001 From: Rob Pike Date: Mon, 1 Nov 2010 17:49:06 -0700 Subject: [PATCH] test/ken/convert.go: add conversion torture test (written by ken) R=ken2 CC=golang-dev https://golang.org/cl/2823042 --- test/ken/convert.go | 431 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 431 insertions(+) create mode 100644 test/ken/convert.go diff --git a/test/ken/convert.go b/test/ken/convert.go new file mode 100644 index 00000000000..3780ec886a4 --- /dev/null +++ b/test/ken/convert.go @@ -0,0 +1,431 @@ +// $G $D/$F.go && $L $F.$A && ./$A.out + +// Copyright 2010 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. + +// near-exhaustive test of converting numbers between types. + +package main + +var i8 int8; +var u8 uint8; +var i16 int16; +var u16 uint16; +var i32 int32; +var u32 uint32; +var i64 int64; +var u64 uint64; +var f32 float32; +var f64 float64; + +type big float64 + +type t struct { + from, to int + val big +} + +const ( + ti8 = iota+1 + tu8 + ti16 + tu16 + ti32 + tu32 + ti64 + tu64 + tf32 + tf64 +) + +var x = []t{ + + /* value good in all types (10) */ + { ti8, ti8, 10 }, { ti8, tu8, 10 }, { ti8, ti16, 10 }, { ti8, tu16, 10 }, + { ti8, ti32, 10 }, { ti8, tu32, 10 }, { ti8, ti64, 10 }, { ti8, tu64, 10 }, + { ti8, tf32, 10 }, { ti8, tf64, 10 }, + + { tu8, ti8, 10 }, { tu8, tu8, 10 }, { tu8, ti16, 10 }, { tu8, tu16, 10 }, + { tu8, ti32, 10 }, { tu8, tu32, 10 }, { tu8, ti64, 10 }, { tu8, tu64, 10 }, + { tu8, tf32, 10 }, { tu8, tf64, 10 }, + + { ti16, ti8, 10 }, { ti16, tu8, 10 }, { ti16, ti16, 10 }, { ti16, tu16, 10 }, + { ti16, ti32, 10 }, { ti16, tu32, 10 }, { ti16, ti64, 10 }, { ti16, tu64, 10 }, + { ti16, tf32, 10 }, { ti16, tf64, 10 }, + + { tu16, ti8, 10 }, { tu16, tu8, 10 }, { tu16, ti16, 10 }, { tu16, tu16, 10 }, + { tu16, ti32, 10 }, { tu16, tu32, 10 }, { tu16, ti64, 10 }, { tu16, tu64, 10 }, + { tu16, tf32, 10 }, { tu16, tf64, 10 }, + + { ti32, ti8, 10 }, { ti32, tu8, 10 }, { ti32, ti16, 10 }, { ti32, tu16, 10 }, + { ti32, ti32, 10 }, { ti32, tu32, 10 }, { ti32, ti64, 10 }, { ti32, tu64, 10 }, + { ti32, tf32, 10 }, { ti32, tf64, 10 }, + + { tu32, ti8, 10 }, { tu32, tu8, 10 }, { tu32, ti16, 10 }, { tu32, tu16, 10 }, + { tu32, ti32, 10 }, { tu32, tu32, 10 }, { tu32, ti64, 10 }, { tu32, tu64, 10 }, + { tu32, tf32, 10 }, { tu32, tf64, 10 }, + + { ti64, ti8, 10 }, { ti64, tu8, 10 }, { ti64, ti16, 10 }, { ti64, tu16, 10 }, + { ti64, ti32, 10 }, { ti64, tu32, 10 }, { ti64, ti64, 10 }, { ti64, tu64, 10 }, + { ti64, tf32, 10 }, { ti64, tf64, 10 }, + + { tu64, ti8, 10 }, { tu64, tu8, 10 }, { tu64, ti16, 10 }, { tu64, tu16, 10 }, + { tu64, ti32, 10 }, { tu64, tu32, 10 }, { tu64, ti64, 10 }, { tu64, tu64, 10 }, + { tu64, tf32, 10 }, { tu64, tf64, 10 }, + + { tf32, ti8, 10 }, { tf32, tu8, 10 }, { tf32, ti16, 10 }, { tf32, tu16, 10 }, + { tf32, ti32, 10 }, { tf32, tu32, 10 }, { tf32, ti64, 10 }, { tf32, tu64, 10 }, + { tf32, tf32, 10 }, { tf32, tf64, 10 }, + + { tf64, ti8, 10 }, { tf64, tu8, 10 }, { tf64, ti16, 10 }, { tf64, tu16, 10 }, + { tf64, ti32, 10 }, { tf64, tu32, 10 }, { tf64, ti64, 10 }, { tf64, tu64, 10 }, + { tf64, tf32, 10 }, { tf64, tf64, 10 }, + + /* value good in all signed types (-4) */ + { ti8, ti8, -4 }, { ti8, ti16, -4 }, + { ti8, ti32, -4 }, { ti8, ti64, -4 }, + { ti8, tf32, -4 }, { ti8, tf64, -4 }, + + { ti16, ti8, -4 }, { ti16, ti16, -4 }, + { ti16, ti32, -4 }, { ti16, ti64, -4 }, + { ti16, tf32, -4 }, + + { ti32, ti8, -4 }, { ti32, ti16, -4 }, + { ti32, ti32, -4 }, { ti32, ti64, -4 }, + { ti32, tf32, -4 }, { ti32, tf64, -4 }, + + { ti64, ti8, -4 }, { ti64, ti16, -4 }, + { ti64, ti32, -4 }, { ti64, ti64, -4 }, + { ti64, tf32, -4 }, + + { tf32, ti8, -4 }, { tf32, ti16, -4 }, + { tf32, ti32, -4 }, { tf32, ti64, -4 }, + { tf32, tf32, -4 }, + + { tf64, ti8, -4 }, { tf64, ti16, -4 }, + { tf64, ti32, -4 }, { tf64, ti64, -4 }, + { tf64, tf32, -4 }, { tf64, tf64, -4 }, + + /* value good in u8 and up (175) */ + { tu8, tu8, 175 }, { tu8, ti16, 175 }, { tu8, tu16, 175 }, + { tu8, ti32, 175 }, { tu8, tu32, 175 }, { tu8, ti64, 175 }, { tu8, tu64, 175 }, + { tu8, tf32, 175 }, { tu8, tf64, 175 }, + + { ti16, tu8, 175 }, { ti16, ti16, 175 }, { ti16, tu16, 175 }, + { ti16, ti32, 175 }, { ti16, tu32, 175 }, { ti16, ti64, 175 }, { ti16, tu64, 175 }, + { ti16, tf32, 175 }, { ti16, tf64, 175 }, + + { tu16, tu8, 175 }, { tu16, ti16, 175 }, { tu16, tu16, 175 }, + { tu16, ti32, 175 }, { tu16, tu32, 175 }, { tu16, ti64, 175 }, { tu16, tu64, 175 }, + { tu16, tf32, 175 }, { tu16, tf64, 175 }, + + { ti32, tu8, 175 }, { ti32, ti16, 175 }, { ti32, tu16, 175 }, + { ti32, ti32, 175 }, { ti32, tu32, 175 }, { ti32, ti64, 175 }, { ti32, tu64, 175 }, + { ti32, tf32, 175 }, { ti32, tf64, 175 }, + + { tu32, tu8, 175 }, { tu32, ti16, 175 }, { tu32, tu16, 175 }, + { tu32, ti32, 175 }, { tu32, tu32, 175 }, { tu32, ti64, 175 }, { tu32, tu64, 175 }, + { tu32, tf32, 175 }, { tu32, tf64, 175 }, + + { ti64, tu8, 175 }, { ti64, ti16, 175 }, { ti64, tu16, 175 }, + { ti64, ti32, 175 }, { ti64, tu32, 175 }, { ti64, ti64, 175 }, { ti64, tu64, 175 }, + { ti64, tf32, 175 }, { ti64, tf64, 175 }, + + { tu64, tu8, 175 }, { tu64, ti16, 175 }, { tu64, tu16, 175 }, + { tu64, ti32, 175 }, { tu64, tu32, 175 }, { tu64, ti64, 175 }, { tu64, tu64, 175 }, + { tu64, tf32, 175 }, { tu64, tf64, 175 }, + + { tf32, tu8, 175 }, { tf32, ti16, 175 }, { tf32, tu16, 175 }, + { tf32, ti32, 175 }, { tf32, tu32, 175 }, { tf32, ti64, 175 }, { tf32, tu64, 175 }, + { tf32, tf32, 175 }, { tf32, tf64, 175 }, + + { tf64, tu8, 175 }, { tf64, ti16, 175 }, { tf64, tu16, 175 }, + { tf64, ti32, 175 }, { tf64, tu32, 175 }, { tf64, ti64, 175 }, { tf64, tu64, 175 }, + { tf64, tf32, 175 }, { tf64, tf64, 175 }, + + /* value good in u16 and up (41259) */ + { tu16, tu16, 41259 }, + { tu16, ti32, 41259 }, { tu16, ti64, 41259 }, { tu16, tu64, 41259 }, + { tu16, tf32, 41259 }, { tu16, tf64, 41259 }, + + { ti32, tu16, 41259 }, + { ti32, ti32, 41259 }, { ti32, tu32, 41259 }, { ti32, ti64, 41259 }, { ti32, tu64, 41259 }, + { ti32, tf32, 41259 }, { ti32, tf64, 41259 }, + + { tu32, tu16, 41259 }, + { tu32, ti32, 41259 }, { tu32, tu32, 41259 }, { tu32, ti64, 41259 }, { tu32, tu64, 41259 }, + { tu32, tf32, 41259 }, { tu32, tf64, 41259 }, + + { ti64, tu16, 41259 }, + { ti64, ti32, 41259 }, { ti64, tu32, 41259 }, { ti64, ti64, 41259 }, { ti64, tu64, 41259 }, + { ti64, tf32, 41259 }, { ti64, tf64, 41259 }, + + { tu64, tu16, 41259 }, + { tu64, ti32, 41259 }, { tu64, tu32, 41259 }, { tu64, ti64, 41259 }, { tu64, tu64, 41259 }, + { tu64, tf32, 41259 }, { tu64, tf64, 41259 }, + + { tf32, tu16, 41259 }, + { tf32, ti32, 41259 }, { tf32, tu32, 41259 }, { tf32, ti64, 41259 }, { tf32, tu64, 41259 }, + { tf32, tf32, 41259 }, { tf32, tf64, 41259 }, + + { tf64, tu16, 41259 }, + { tf64, ti32, 41259 }, { tf64, tu32, 41259 }, { tf64, ti64, 41259 }, { tf64, tu64, 41259 }, + { tf64, tf32, 41259 }, { tf64, tf64, 41259 }, + + /* value good in u32 and up (3758096384) */ + { tu32, tu32, 3758096384 }, { tu32, ti64, 3758096384 }, { tu32, tu64, 3758096384 }, + { tu32, tf32, 3758096384 }, { tu32, tf64, 3758096384 }, + + { ti64, tu32, 3758096384 }, { ti64, ti64, 3758096384 }, { ti64, tu64, 3758096384 }, + { ti64, tf32, 3758096384 }, { ti64, tf64, 3758096384 }, + + { tu64, tu32, 3758096384 }, { tu64, ti64, 3758096384 }, { tu64, tu64, 3758096384 }, + { tu64, tf32, 3758096384 }, { tu64, tf64, 3758096384 }, + + { tf32, tu32, 3758096384 }, { tf32, ti64, 3758096384 }, { tf32, tu64, 3758096384 }, + { tf32, tf32, 3758096384 }, { tf32, tf64, 3758096384 }, + + { tf64, tu32, 3758096384 }, { tf64, ti64, 3758096384 }, { tf64, tu64, 3758096384 }, + { tf64, tf32, 3758096384 }, { tf64, tf64, 3758096384 }, + + /* value good in u64 and up (16717361816799281152) */ + { tu64, tu64, 16717361816799281152 }, + { tu64, tf32, 16717361816799281152 }, { tu64, tf64, 16717361816799281152 }, + + { tf32, tu64, 16717361816799281152 }, + { tf32, tf32, 16717361816799281152 }, { tf32, tf64, 16717361816799281152 }, + + { tf64, tu64, 16717361816799281152 }, + { tf64, tf32, 16717361816799281152 }, { tf64, tf64, 16717361816799281152 }, +} + +func main() { + for i:=0; i