(&self, name: &SymbolKey, exp_array: &ExpArray)
| 1046 | } |
| 1047 | |
| 1048 | fn check_array(&self, name: &SymbolKey, exp_array: &ExpArray) { |
| 1049 | let mut exp_contents = HashMap::with_capacity(exp_array.contents.len()); |
| 1050 | for (subscripts, value) in exp_array.contents.iter() { |
| 1051 | assert_eq!( |
| 1052 | exp_array.dimensions.len(), |
| 1053 | subscripts.len(), |
| 1054 | "Expected array {} has wrong number of subscripts", |
| 1055 | name |
| 1056 | ); |
| 1057 | for (i, subscript) in subscripts.iter().enumerate() { |
| 1058 | assert!( |
| 1059 | *subscript >= 0 && *subscript < exp_array.dimensions[i] as i32, |
| 1060 | "Expected array {} has out-of-bounds subscript {} at dimension {}", |
| 1061 | name, |
| 1062 | subscript, |
| 1063 | i |
| 1064 | ); |
| 1065 | } |
| 1066 | let previous = exp_contents.insert(subscripts.clone(), value.clone()); |
| 1067 | assert!(previous.is_none(), "Expected array {} has duplicate subscripts", name); |
| 1068 | } |
| 1069 | |
| 1070 | let default_value = match exp_array.subtype { |
| 1071 | ExprType::Boolean => ConstantDatum::Boolean(false), |
| 1072 | ExprType::Double => ConstantDatum::Double(0.0), |
| 1073 | ExprType::Integer => ConstantDatum::Integer(0), |
| 1074 | ExprType::Text => ConstantDatum::Text(String::new()), |
| 1075 | }; |
| 1076 | |
| 1077 | let mut subscripts = vec![0; exp_array.dimensions.len()]; |
| 1078 | loop { |
| 1079 | let value = self |
| 1080 | .query_array_element(name, &subscripts) |
| 1081 | .unwrap_or_else(|| panic!("Expected array {} not defined", name)); |
| 1082 | assert_eq!( |
| 1083 | exp_contents.get(&subscripts).unwrap_or(&default_value), |
| 1084 | &value, |
| 1085 | "Expected array {} at {:?} has wrong value", |
| 1086 | name, |
| 1087 | subscripts |
| 1088 | ); |
| 1089 | |
| 1090 | let mut i = 0; |
| 1091 | while i < subscripts.len() { |
| 1092 | subscripts[i] += 1; |
| 1093 | if subscripts[i] < exp_array.dimensions[i] as i32 { |
| 1094 | break; |
| 1095 | } |
| 1096 | subscripts[i] = 0; |
| 1097 | i += 1; |
| 1098 | } |
| 1099 | if i == subscripts.len() { |
| 1100 | break; |
| 1101 | } |
| 1102 | } |
| 1103 | |
| 1104 | self.check_array_dims(name, &exp_array.dimensions); |
| 1105 | } |
no test coverage detected