csdl.test 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515
  1. #--------------------------------------------------------*-Tcl-*--
  2. #
  3. # csdl.test
  4. #
  5. # This package of tests exercises the Cross Section
  6. # Description Language (CSDL) classes to ensure their
  7. # functionality.
  8. #
  9. # Tests are broken out into several categories
  10. # llcsdl - low level csdl classes
  11. # hlcsdl - high level csdl classes
  12. # stackup - stackup class exercises
  13. #
  14. # Source this script to run the tests.
  15. #
  16. # Bob Techentin
  17. # August 28, 2001
  18. #
  19. # Copyright 2001-2004 Mayo Foundation. All rights reserved.
  20. # $Id: csdl.test,v 1.1 2004/02/13 21:07:27 techenti Exp $
  21. #
  22. #-----------------------------------------------------------------
  23. #-----------------------------------------------------------------
  24. # Put the current directory first in the package path.
  25. # (Actually, put the parent fo the current directory in
  26. # the path, as csdl_shapes requires the units package,
  27. # which should be in a sibling directory.)
  28. #-----------------------------------------------------------------
  29. set auto_path [concat [file join [file dirname [info script]] ..] $auto_path]
  30. #-----------------------------------------------------------------
  31. # Load the tcltest package and import the test command
  32. #-----------------------------------------------------------------
  33. if {[lsearch [namespace children] ::tcltest] == -1} {
  34. package require tcltest
  35. namespace import -force ::tcltest::*
  36. }
  37. #-----------------------------------------------------------------
  38. # Load CSDL
  39. #-----------------------------------------------------------------
  40. if {[catch {package require csdl} msg]} {
  41. catch {puts stderr "Cannot load csdl package: '$msg'"}
  42. return
  43. }
  44. #-----------------------------------------------------------------
  45. # test visitor class
  46. # This class can exercise the visitor capabilities of
  47. # the various CSDL classes by simply recording who
  48. # it is visiting.
  49. #-----------------------------------------------------------------
  50. catch {itcl::delete class test-visitor}
  51. itcl::class test-visitor {
  52. variable result {}
  53. set classTypes {
  54. Stackup GroundPlane DielectricLayer
  55. RectangleConductors TrapezoidConductors CircleConductors
  56. Dielectric Conductor Ground
  57. Rectangle Trapezoid Circle Layer
  58. }
  59. # Create a visit method for each class type
  60. foreach type $classTypes {
  61. method visit$type {obj x y} \
  62. "lappend result \"$type \$obj \$x \$y\""
  63. }
  64. method clear {} {set result [list]}
  65. method result {} {return $result}
  66. }
  67. #----------------------------------------------------------
  68. # Shape tests
  69. #----------------------------------------------------------
  70. #----------------------------------------------------------
  71. # Instantiation tests
  72. #----------------------------------------------------------
  73. test shape-1.0 {instantiate Shape} {
  74. # In a perfect world, this would be a pure virtual
  75. # class, and we couldn't instantiate it.
  76. catch {itcl::delete object s0}
  77. set obj [Shape s0]
  78. itcl::delete object $obj
  79. set obj
  80. } {s0}
  81. test shape-1.1 {instantiate Rectangle} {
  82. catch {itcl::delete object r0}
  83. set obj [Rectangle r0]
  84. itcl::delete object $obj
  85. set obj
  86. } {r0}
  87. test shape-1.2 {instantiate Trapezoid} {
  88. catch {itcl::delete object t0}
  89. set obj [Trapezoid t0]
  90. itcl::delete object $obj
  91. set obj
  92. } {t0}
  93. test shape-1.3 {instantiate Circle} {
  94. catch {itcl::delete object c0}
  95. set obj [Circle c0]
  96. itcl::delete object $obj
  97. set obj
  98. } {c0}
  99. test shape-1.4 {instantiate Layer} {
  100. catch {itcl::delete object layer0}
  101. set obj [Layer layer0]
  102. itcl::delete object $obj
  103. set obj
  104. } {layer0}
  105. #----------------------------------------------------------
  106. # Basic Shape tests
  107. #
  108. # This looks a little strange, but this seems like
  109. # a good way to run a bunch of shape tests on
  110. # different kinds of shape objects, like rectangles
  111. # circles, etc.
  112. #
  113. # The test procedures call this proc, which runs tests
  114. # based on the object class argument. All shape classes
  115. # should be able to pass these basic functionality tests.
  116. #----------------------------------------------------------
  117. proc basic-shape-tests {objClass} {
  118. catch {itcl::delete object obj0}
  119. catch {itcl::delete object v}
  120. # First, make sure that this objClass is really
  121. # a subclass of shape
  122. test shape-$objClass-1.0 "$objClass must be subclass of Shape" {
  123. catch {itcl::delete object obj0}
  124. $objClass obj0
  125. set result [obj0 isa Shape]
  126. itcl::delete object obj0
  127. set result
  128. } {1}
  129. test shape-$objClass-1.1 "Define $objClass name" {
  130. catch {itcl::delete object obj0}
  131. $objClass obj0 -name "$objClass object"
  132. set result [obj0 cget -name]
  133. itcl::delete object obj0
  134. set result
  135. } "$objClass object"
  136. test shape-$objClass-1.2 "Define $objClass color" {
  137. catch {itcl::delete object obj0}
  138. $objClass obj0 -color "green"
  139. set result [obj0 cget -color]
  140. itcl::delete object obj0
  141. set result
  142. } {green}
  143. test shape-$objClass-1.3 "Define $objClass description" {
  144. catch {itcl::delete object obj0}
  145. $objClass obj0 -description "default $objClass"
  146. set result [obj0 cget -description]
  147. itcl::delete object obj0
  148. set result
  149. } "default $objClass"
  150. test shape-$objClass-1.4 "Accept a visitor" {
  151. catch {itcl::delete object v}
  152. catch {itcl::delete object obj0}
  153. test-visitor v
  154. $objClass obj0
  155. obj0 accept v 10 10
  156. set result [v result]
  157. itcl::delete object v obj0
  158. set result
  159. } "{$objClass ::obj0 10 10}"
  160. }
  161. #----------------------------------------------------------
  162. # Rectangle tests
  163. #----------------------------------------------------------
  164. basic-shape-tests Rectangle
  165. test shape-2.1 {Rectangle with height and width} {
  166. catch {itcl::delete object r0}
  167. set obj [Rectangle r0 -width 10 -height 10]
  168. itcl::delete object $obj
  169. set obj
  170. } {r0}
  171. test shape-2.2 {Rectangle with width units} {
  172. catch {itcl::delete object r0}
  173. set obj [Rectangle r0 -width 20micron]
  174. itcl::delete object $obj
  175. set obj
  176. } {r0}
  177. test shape-2.3 {Rectangle with height units} {
  178. catch {itcl::delete object r0}
  179. set obj [Rectangle r0 -height 20micron]
  180. itcl::delete object $obj
  181. set obj
  182. } {r0}
  183. test shape-2.4 {Rectangle with invalid width} {
  184. catch {itcl::delete object r0}
  185. catch {Rectangle r0 -width 10seconds} result
  186. set result
  187. } {Invalid Dimension 'width': '10seconds' and 'meter' have incompatible units}
  188. test shape-2.5 {Rectangle with invalid height} {
  189. catch {itcl::delete object r0}
  190. catch {Rectangle r0 -height 10seconds} result
  191. set result
  192. } {Invalid Dimension 'height': '10seconds' and 'meter' have incompatible units}
  193. test shape-2.6 {Rectangle width conversion} {
  194. catch {itcl::delete object r0}
  195. Rectangle r0 -width 20micron
  196. set result [expr {[r0 width] == 2e-5}]
  197. itcl::delete object r0
  198. set result
  199. } {1}
  200. test shape-2.7 {Rectangle height conversion} {
  201. catch {itcl::delete object r0}
  202. Rectangle r0 -height 20micron
  203. set result [expr {[r0 height] == 2e-5}]
  204. itcl::delete object r0
  205. set result
  206. } {1}
  207. test shape-2.8 {Rectangle area} {
  208. catch {itcl::delete object r0}
  209. Rectangle r0 -height 20 -width 10
  210. set result [expr {[r0 area] == 200}]
  211. itcl::delete object r0
  212. set result
  213. } {1}
  214. test shape-2.9 {Rectangle area conversion} {
  215. catch {itcl::delete object r0}
  216. Rectangle r0 -height 20mm -width 10mm
  217. set result [expr {[r0 area] == 2e-4}]
  218. itcl::delete object r0
  219. set result
  220. } {1}
  221. test shape-2.10 {Rectangle circumference} {
  222. catch {itcl::delete object r0}
  223. Rectangle r0 -height 20 -width 10
  224. set result [expr {[r0 circumference] == 60}]
  225. itcl::delete object r0
  226. set result
  227. } {1}
  228. test shape-2.11 {Rectangle circumference conversion} {
  229. catch {itcl::delete object r0}
  230. Rectangle r0 -height 20mm -width 10mm
  231. set result [expr {[r0 circumference] == 0.06}]
  232. itcl::delete object r0
  233. set result
  234. } {1}
  235. #----------------------------------------------------------
  236. # Trapezoid tests
  237. #----------------------------------------------------------
  238. basic-shape-tests Trapezoid
  239. test shape-3.1 {Trapezoid with height and widths} {
  240. catch {itcl::delete object t0}
  241. set obj [Trapezoid t0 -topWidth 10 -bottomWidth 15 -height 10]
  242. itcl::delete object $obj
  243. set obj
  244. } {t0}
  245. test shape-3.2 {Trapezoid with top width units} {
  246. catch {itcl::delete object t0}
  247. set obj [Trapezoid t0 -topWidth 20micron]
  248. itcl::delete object $obj
  249. set obj
  250. } {t0}
  251. test shape-3.3 {Trapezoid with bottom width units} {
  252. catch {itcl::delete object t0}
  253. set obj [Trapezoid t0 -bottomWidth 20micron]
  254. itcl::delete object $obj
  255. set obj
  256. } {t0}
  257. test shape-3.4 {Trapezoid with height units} {
  258. catch {itcl::delete object t0}
  259. set obj [Trapezoid t0 -height 20micron]
  260. itcl::delete object $obj
  261. set obj
  262. } {t0}
  263. test shape-3.5 {Trapezoid with invalid top width} {
  264. catch {itcl::delete object t0}
  265. catch {Trapezoid t0 -topWidth 10seconds} result
  266. set result
  267. } {Invalid Dimension 'top width': '10seconds' and 'meter' have incompatible units}
  268. test shape-3.6 {Trapezoid with invalid bottom width} {
  269. catch {itcl::delete object t0}
  270. catch {Trapezoid t0 -bottomWidth 10seconds} result
  271. set result
  272. } {Invalid Dimension 'bottom width': '10seconds' and 'meter' have incompatible units}
  273. test shape-3.7 {Trapezoid with invalid height} {
  274. catch {itcl::delete object t0}
  275. catch {Trapezoid t0 -height 10seconds} result
  276. set result
  277. } {Invalid Dimension 'height': '10seconds' and 'meter' have incompatible units}
  278. test shape-3.8 {Trapezoid top width conversion} {
  279. catch {itcl::delete object t0}
  280. Trapezoid t0 -topWidth 20micron -bottomWidth 10micron
  281. set result [expr {[t0 width] == 2e-5}]
  282. itcl::delete object t0
  283. set result
  284. } {1}
  285. test shape-3.9 {Trapezoid height conversion} {
  286. catch {itcl::delete object t0}
  287. Trapezoid t0 -height 20micron
  288. set result [expr {[t0 height] == 2e-5}]
  289. itcl::delete object t0
  290. set result
  291. } {1}
  292. test shape-3.10 {Trapezoid area} {
  293. catch {itcl::delete object t0}
  294. Trapezoid t0 -height 10 -bottomWidth 30 -topWidth 20
  295. set result [expr {[t0 area] == 250}]
  296. itcl::delete object t0
  297. set result
  298. } {1}
  299. test shape-3.11 {Trapezoid area conversion} {
  300. catch {itcl::delete object t0}
  301. Trapezoid t0 -height 10cm -bottomWidth 30cm -topWidth 20cm
  302. set result [expr {[t0 area] == 250e-4}]
  303. itcl::delete object t0
  304. set result
  305. } {1}
  306. test shape-3.12 {Trapezoid circumference} {
  307. catch {itcl::delete object t0}
  308. Trapezoid t0 -height 3 -bottomWidth 18 -topWidth 10
  309. set result [expr {[t0 circumference] == 38}]
  310. itcl::delete object t0
  311. set result
  312. } {1}
  313. test shape-3.13 {Trapezoid circumference conversion} {
  314. catch {itcl::delete object t0}
  315. Trapezoid t0 -height 3cm -bottomWidth 18cm -topWidth 10cm
  316. set result [expr {[t0 circumference] == 38e-2}]
  317. itcl::delete object t0
  318. set result
  319. } {1}
  320. #----------------------------------------------------------
  321. # Circle tests
  322. #----------------------------------------------------------
  323. basic-shape-tests Circle
  324. test shape-4.1 {Circle with diameter} {
  325. catch {itcl::delete object c0}
  326. set obj [Circle c0 -diameter 10]
  327. itcl::delete object $obj
  328. set obj
  329. } {c0}
  330. test shape-4.2 {Circle with diameter units} {
  331. catch {itcl::delete object c0}
  332. set obj [Circle c0 -diameter 20micron]
  333. itcl::delete object $obj
  334. set obj
  335. } {c0}
  336. test shape-4.3 {Circle with invalid diameter} {
  337. catch {itcl::delete object c0}
  338. catch {Circle c0 -diameter 10seconds} result
  339. set result
  340. } {Invalid Dimension 'diameter': '10seconds' and 'meter' have incompatible units}
  341. test shape-4.4 {Circle width conversion} {
  342. catch {itcl::delete object c0}
  343. Circle c0 -diameter 20micron
  344. set result [expr {[c0 width] == 2e-5}]
  345. itcl::delete object c0
  346. set result
  347. } {1}
  348. test shape-4.5 {Circle height conversion} {
  349. catch {itcl::delete object c0}
  350. Circle c0 -diameter 20micron
  351. set result [expr {[c0 height] == 2e-5}]
  352. itcl::delete object c0
  353. set result
  354. } {1}
  355. test shape-4.6 {Circle area} {
  356. catch {itcl::delete object c0}
  357. Circle c0 -diameter 10
  358. set result [expr {[c0 area] - 78.5398163397 < 1e-7}]
  359. itcl::delete object c0
  360. set result
  361. } {1}
  362. test shape-4.7 {Circle area conversion} {
  363. catch {itcl::delete object c0}
  364. Circle c0 -diameter 10cm
  365. set result [expr {[c0 area] - 0.00785398163397 < 1e-12}]
  366. itcl::delete object c0
  367. set result
  368. } {1}
  369. test shape-4.8 {Circle circumference} {
  370. catch {itcl::delete object c0}
  371. Circle c0 -diameter 10
  372. set result [expr {[c0 circumference] - 31.415926535 < 1e-8}]
  373. itcl::delete object c0
  374. set result
  375. } {1}
  376. test shape-4.9 {Circle circumference conversion} {
  377. catch {itcl::delete object c0}
  378. Circle c0 -diameter 10cm
  379. set result [expr {[c0 circumference] - 0.31415926535 < 1e-10}]
  380. itcl::delete object c0
  381. set result
  382. } {1}
  383. #----------------------------------------------------------
  384. # Layer tests
  385. #----------------------------------------------------------
  386. basic-shape-tests Layer
  387. test shape-5.1 {Layer with thickness} {
  388. catch {itcl::delete object layer0}
  389. set obj [Layer layer0 -thickness 10]
  390. itcl::delete object $obj
  391. set obj
  392. } {layer0}
  393. test shape-5.2 {Layer with thickness units} {
  394. catch {itcl::delete object layer0}
  395. set obj [Layer layer0 -thickness 20micron]
  396. itcl::delete object $obj
  397. set obj
  398. } {layer0}
  399. test shape-5.3 {Layer with invalid thickness} {
  400. catch {itcl::delete object layer0}
  401. catch {Layer layer0 -thickness 10seconds} result
  402. set result
  403. } {Invalid Dimension 'thickness': '10seconds' and 'meter' have incompatible units}
  404. test shape-5.4 {Layer width conversion} {
  405. catch {itcl::delete object layer0}
  406. Layer layer0 -thickness 20micron
  407. set result [expr {[layer0 width] == 4e-5}]
  408. itcl::delete object layer0
  409. set result
  410. } {1}
  411. test shape-5.5 {Layer height conversion} {
  412. catch {itcl::delete object layer0}
  413. Layer layer0 -thickness 20micron
  414. set result [expr {[layer0 height] == 2e-5}]
  415. itcl::delete object layer0
  416. set result
  417. } {1}
  418. #----------------------------------------------------------
  419. # Instantiation Tests - make sure the classes exist
  420. #----------------------------------------------------------
  421. test llcsdl-1.0 {instantiate Dielectric} {
  422. set obj [Dielectric dielectric0 -shape [Layer layer0 -thickness 10]]
  423. itcl::delete object dielectric0 layer0
  424. set obj
  425. } {dielectric0}
  426. ::tcltest::cleanupTests