1######################################################################## 2# # 3# This software is part of the ast package # 4# Copyright (c) 1982-2011 AT&T Intellectual Property # 5# and is licensed under the # 6# Eclipse Public License, Version 1.0 # 7# by AT&T Intellectual Property # 8# # 9# A copy of the License is available at # 10# http://www.eclipse.org/org/documents/epl-v10.html # 11# (with md5 checksum b35adb5213ca9657e911e9befb180842) # 12# # 13# Information and Software Systems Research # 14# AT&T Research # 15# Florham Park NJ # 16# # 17# David Korn <dgk@research.att.com> # 18# # 19######################################################################## 20function err_exit 21{ 22 print -u2 -n "\t" 23 print -u2 -r ${Command}[$1]: "${@:2}" 24 (( Errors+=1 )) 25} 26alias err_exit='err_exit $LINENO' 27 28Command=${0##*/} 29integer Errors=0 30 31typeset -T Pt_t=( 32 float x=1 33 float y=0 34 len() 35 { 36 print -r $((sqrt(_.x*_.x + _.y*_.y))) 37 } 38) 39 40typeset -T Rect_t=( 41 Pt_t ll=(x=0 y=0) 42 Pt_t ur=(x=1 y=1) 43 area() 44 { 45 print -r $(( abs((_.ur.x-_.ll.x)*(_.ur.y-_.ll.y)) )) 46 } 47) 48 49for ((i=0; i < 100; i++)) 50do 51Rect_t r 52[[ ${r.area} == 1 ]] || err_exit '${r.area} != 1' 53Rect_t s=( 54 Pt_t ur=(x=9 y=9) 55 Pt_t ll=(x=7 y=7) 56) 57[[ ${s.ur.x} == 9 ]] || err_exit ' ${s.ur.x} != 9' 58(( s.ur.x == 9 ))|| err_exit ' ((s.ur.x)) != 9' 59[[ ${s.ll.y} == 7 ]] || err_exit '${s.ll.y} != 7' 60(( s.area == 4 )) || err_exit 'area of s should be 4' 61[[ ${s.area} == 4 ]] || err_exit '${s.area} != 4' 62unset r s 63done 64Rect_t -A r 65r[one]=(ur=(x=4 y=4)) 66(( r[one].area == 16 )) || err_exit 'area of r[one] should be 16' 67[[ ${r[one].area} == 16 ]] || err_exit '${r[one].area} should be 16' 68unset r 69 70exit $((Errors<125?Errors:125)) 71