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

Function test_named_contexts

ciphercore-base/src/graphs.rs:5436–5561  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

5434
5435 #[test]
5436 fn test_named_contexts() {
5437 let helper = || -> Result<Context> {
5438 let context = create_context()?;
5439 let graph = context.create_graph()?;
5440 let input_a = graph.input(scalar_type(INT32))?;
5441 let input_b = graph.input(scalar_type(INT32))?;
5442 let output = graph.add(input_a.clone(), input_b.clone())?;
5443 graph.set_output_node(output.clone())?;
5444 graph.finalize()?;
5445 context.set_main_graph(graph.clone())?;
5446 assert!(context.get_graph_name(graph.clone()).is_err());
5447 assert!(context.retrieve_graph("main").is_err());
5448 assert!(context.get_node_name(input_a.clone())?.is_none());
5449 assert!(context.retrieve_node(graph.clone(), "a").is_err());
5450 context.set_graph_name(graph.clone(), "main")?;
5451 context.set_node_name(input_a.clone(), "a")?;
5452 assert!(context.retrieve_node(graph.clone(), "b").is_err());
5453 context.set_node_name(input_b.clone(), "b")?;
5454 context.finalize()?;
5455 assert_eq!(context.get_graph_name(graph.clone())?, "main");
5456 assert_eq!(
5457 context.get_node_name(input_a.clone())?,
5458 Some("a".to_owned())
5459 );
5460 assert_eq!(
5461 context.get_node_name(input_b.clone())?,
5462 Some("b".to_owned())
5463 );
5464 assert!(context.retrieve_node(graph.clone(), "a")? == input_a.clone());
5465 Ok(context)
5466 };
5467 let context = helper().unwrap();
5468 let helper2 = |context: Context| -> Result<i32> {
5469 let other_context = create_context()?;
5470 let other_graph = other_context.create_graph()?;
5471 let input = other_graph.input(scalar_type(BIT))?;
5472 let other_input = other_graph.input(scalar_type(BIT))?;
5473 assert!(context
5474 .prepare_input_values::<Value>(other_graph.clone(), HashMap::new())
5475 .is_err());
5476 assert!(other_context
5477 .prepare_input_values::<Value>(
5478 other_graph.clone(),
5479 HashMap::from_iter([("a", Value::from_scalar(123, INT32)?)])
5480 )
5481 .is_err());
5482 other_context.set_node_name(input, "b")?;
5483 assert!(other_context
5484 .prepare_input_values::<Value>(
5485 other_graph.clone(),
5486 HashMap::from_iter([("a", Value::from_scalar(123, INT32)?)])
5487 )
5488 .is_err());
5489 assert!(other_context
5490 .prepare_input_values::<Value>(
5491 other_graph.clone(),
5492 HashMap::from_iter([("b", Value::from_scalar(123, INT32)?)])
5493 )

Callers

nothing calls this directly

Calls 15

random_evaluateFunction · 0.85
cloneMethod · 0.80
prepare_input_valuesMethod · 0.80
to_i32Method · 0.80
create_contextFunction · 0.70
scalar_typeFunction · 0.70
create_graphMethod · 0.45
inputMethod · 0.45
addMethod · 0.45
set_output_nodeMethod · 0.45
finalizeMethod · 0.45
set_main_graphMethod · 0.45

Tested by

no test coverage detected