| 
									
										
										
										
											2025-03-20 11:06:27 +13:00
										 |  |  | --- | 
					
						
							|  |  |  | source: kcl-lib/src/simulation_tests.rs | 
					
						
							|  |  |  | description: Result of unparsing computed_var.kcl | 
					
						
							|  |  |  | --- | 
					
						
							|  |  |  | // This tests computed properties. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | arr = [0, 0, 0, 10] | 
					
						
							|  |  |  | i = 3 | 
					
						
							|  |  |  | ten = arr[i] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-04-22 12:44:52 -05:00
										 |  |  | assert(ten, isEqualTo = 10, error = "oops") | 
					
						
							| 
									
										
										
										
											2025-03-20 11:06:27 +13:00
										 |  |  | 
 | 
					
						
							|  |  |  | p = "foo" | 
					
						
							|  |  |  | obj = { foo = 1, bar = 0 } | 
					
						
							|  |  |  | one = obj[p] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-04-22 12:44:52 -05:00
										 |  |  | assert(one, isEqualTo = 1, error = "oops") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | assert( | 
					
						
							|  |  |  |   PI, | 
					
						
							|  |  |  |   isEqualTo = 3, | 
					
						
							|  |  |  |   tolerance = 0.2, | 
					
						
							|  |  |  |   error = "oops pi", | 
					
						
							|  |  |  | ) | 
					
						
							| 
									
										
										
										
											2025-03-20 11:06:27 +13:00
										 |  |  | 
 | 
					
						
							|  |  |  | x = cos(2 * PI) | 
					
						
							| 
									
										
										
										
											2025-04-22 12:44:52 -05:00
										 |  |  | assert( | 
					
						
							|  |  |  |   x, | 
					
						
							|  |  |  |   isEqualTo = 1, | 
					
						
							|  |  |  |   tolerance = 0.000001, | 
					
						
							|  |  |  |   error = "oops cos", | 
					
						
							|  |  |  | ) |