MCPcopy Create free account
hub / github.com/ciphermodelabs/ciphercore / test_well_behaved

Function test_well_behaved

ciphercore-base/src/ops/clip.rs:136–189  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

134
135 #[test]
136 fn test_well_behaved() {
137 || -> Result<()> {
138 let c = simple_context(|g| {
139 let i = g.input(array_type(vec![19, 64], BIT))?;
140 g.custom_op(CustomOperation::new(Clip2K { k: 10 }), vec![i])
141 })?;
142 let mapped_c = run_instantiation_pass(c)?;
143 let inputs = Value::from_flattened_array(
144 &vec![
145 0,
146 1,
147 -1,
148 2,
149 -2,
150 1023,
151 -1023,
152 1024,
153 -1024,
154 1025,
155 -1025,
156 2048,
157 -2048,
158 2047,
159 -2047,
160 2049,
161 -2049,
162 i64::MIN,
163 i64::MAX,
164 ],
165 INT64,
166 )?;
167 let result_v = random_evaluate(mapped_c.get_context().get_main_graph()?, vec![inputs])?
168 .to_flattened_array_u64(array_type(vec![19], INT64))?;
169 assert_eq!(
170 result_v,
171 vec![0, 1, 0, 2, 0, 1023, 0, 1024, 0, 1024, 0, 1024, 0, 1024, 0, 1024, 0, 0, 1024]
172 );
173 Ok(())
174 }()
175 .unwrap();
176 || -> Result<()> {
177 let c = simple_context(|g| {
178 let i = g.input(array_type(vec![64], BIT))?;
179 g.custom_op(CustomOperation::new(Clip2K { k: 20 }), vec![i])
180 })?;
181 let mapped_c = run_instantiation_pass(c)?;
182 let inputs = Value::from_scalar(123456789, INT64)?;
183 let result_v = random_evaluate(mapped_c.get_context().get_main_graph()?, vec![inputs])?
184 .to_u64(INT64)?;
185 assert_eq!(result_v, 1 << 20);
186 Ok(())
187 }()
188 .unwrap();
189 }
190
191 #[test]
192 fn test_malformed() {

Callers

nothing calls this directly

Calls 10

simple_contextFunction · 0.85
run_instantiation_passFunction · 0.85
random_evaluateFunction · 0.85
array_typeFunction · 0.50
inputMethod · 0.45
custom_opMethod · 0.45
get_main_graphMethod · 0.45
get_contextMethod · 0.45
to_u64Method · 0.45

Tested by

no test coverage detected