ArmNN
 21.02
ObservableTest.cpp File Reference
#include <boost/test/unit_test.hpp>
#include "Graph.hpp"
#include "Observable.hpp"

Go to the source code of this file.

Functions

 BOOST_AUTO_TEST_CASE (AddedLayerObservableTest)
 
 BOOST_AUTO_TEST_CASE (ClearAddedLayerObservableTest)
 
 BOOST_AUTO_TEST_CASE (ErasedLayerNamesObservableTest)
 
 BOOST_AUTO_TEST_CASE (ClearErasedLayerNamesObservableTest)
 

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/4]

BOOST_AUTO_TEST_CASE ( AddedLayerObservableTest  )

Definition at line 13 of file ObservableTest.cpp.

References Graph::AddLayer(), GraphObservable< ObservedType >::begin(), GraphObservable< ObservedType >::end(), and Graph::InsertNewLayer().

14 {
15  armnn::Graph graph;
16 
17  // Create a graph observable
18  armnn::AddedLayerObservable layerObservable(graph);
19 
20  // Add a few layers
21  auto output = graph.AddLayer<armnn::OutputLayer>(0, "output");
22  auto input = graph.InsertNewLayer<armnn::InputLayer>(output->GetInputSlot(0), 0, "input");
23 
24  // Check the observable has observed the changes
25  std::list<armnn::Layer*> testLayers({ output, input });
26 
27  BOOST_CHECK_EQUAL_COLLECTIONS(layerObservable.begin(), layerObservable.end(),
28  testLayers.begin(), testLayers.end());
29 }
LayerT * AddLayer(Args &&... args)
Adds a new layer, of type LayerType, to the graph constructed with the arguments passed.
Definition: Graph.hpp:402
A layer user-provided data can be bound to (e.g. inputs, outputs).
Definition: OutputLayer.hpp:13
A layer user-provided data can be bound to (e.g. inputs, outputs).
Definition: InputLayer.hpp:13
LayerT * InsertNewLayer(InputSlot &insertBefore, Args &&... args)
Inserts a new layer between the output slot currently connected to insertBefore and insertBefore itse...
Definition: Graph.hpp:416

◆ BOOST_AUTO_TEST_CASE() [2/4]

BOOST_AUTO_TEST_CASE ( ClearAddedLayerObservableTest  )

Definition at line 31 of file ObservableTest.cpp.

References Graph::AddLayer(), GraphObservable< ObservedType >::begin(), GraphObservable< ObservedType >::Clear(), GraphObservable< ObservedType >::end(), and Graph::InsertNewLayer().

32 {
33  armnn::Graph graph;
34 
35  // Create a graph observable
36  armnn::AddedLayerObservable addedLayerObservable(graph);
37 
38  // Add a few layers
39  auto output = graph.AddLayer<armnn::OutputLayer>(0, "output");
40  graph.InsertNewLayer<armnn::InputLayer>(output->GetInputSlot(0), 0, "input");
41 
42  addedLayerObservable.Clear();
43 
44  // Check the observable has observed the changes
45  std::list<armnn::Layer*> emptyList({});
46 
47  BOOST_CHECK_EQUAL_COLLECTIONS(addedLayerObservable.begin(), addedLayerObservable.end(),
48  emptyList.begin(), emptyList.end());
49 }
LayerT * AddLayer(Args &&... args)
Adds a new layer, of type LayerType, to the graph constructed with the arguments passed.
Definition: Graph.hpp:402
A layer user-provided data can be bound to (e.g. inputs, outputs).
Definition: OutputLayer.hpp:13
A layer user-provided data can be bound to (e.g. inputs, outputs).
Definition: InputLayer.hpp:13
LayerT * InsertNewLayer(InputSlot &insertBefore, Args &&... args)
Inserts a new layer between the output slot currently connected to insertBefore and insertBefore itse...
Definition: Graph.hpp:416

◆ BOOST_AUTO_TEST_CASE() [3/4]

BOOST_AUTO_TEST_CASE ( ErasedLayerNamesObservableTest  )

Definition at line 51 of file ObservableTest.cpp.

References Graph::AddLayer(), GraphObservable< ObservedType >::begin(), GraphObservable< ObservedType >::end(), Graph::EraseLayer(), and Graph::InsertNewLayer().

52 {
53  armnn::Graph graph;
54 
55  // Create a graph observable
56  armnn::ErasedLayerNamesObservable erasedLayerNamesObservable(graph);
57 
58  // Add a few layers
59  auto output = graph.AddLayer<armnn::OutputLayer>(0, "output");
60  graph.InsertNewLayer<armnn::InputLayer>(output->GetInputSlot(0), 0, "input");
61 
62  graph.EraseLayer(output);
63 
64  // Check the observable has observed the changes
65  std::list<std::string> testList({"output"});
66 
67  BOOST_CHECK_EQUAL_COLLECTIONS(erasedLayerNamesObservable.begin(), erasedLayerNamesObservable.end(),
68  testList.begin(), testList.end());
69 }
LayerT * AddLayer(Args &&... args)
Adds a new layer, of type LayerType, to the graph constructed with the arguments passed.
Definition: Graph.hpp:402
void EraseLayer(Iterator pos)
Deletes the layer at the specified position.
Definition: Graph.hpp:449
A layer user-provided data can be bound to (e.g. inputs, outputs).
Definition: OutputLayer.hpp:13
A layer user-provided data can be bound to (e.g. inputs, outputs).
Definition: InputLayer.hpp:13
LayerT * InsertNewLayer(InputSlot &insertBefore, Args &&... args)
Inserts a new layer between the output slot currently connected to insertBefore and insertBefore itse...
Definition: Graph.hpp:416

◆ BOOST_AUTO_TEST_CASE() [4/4]

BOOST_AUTO_TEST_CASE ( ClearErasedLayerNamesObservableTest  )

Definition at line 71 of file ObservableTest.cpp.

References Graph::AddLayer(), GraphObservable< ObservedType >::begin(), BOOST_AUTO_TEST_SUITE_END(), GraphObservable< ObservedType >::Clear(), GraphObservable< ObservedType >::end(), Graph::EraseLayer(), and Graph::InsertNewLayer().

72 {
73  armnn::Graph graph;
74 
75  // Create a graph observable
76  armnn::ErasedLayerNamesObservable erasedLayerNamesObservable(graph);
77 
78  // Add a few layers
79  auto output = graph.AddLayer<armnn::OutputLayer>(0, "output");
80  graph.InsertNewLayer<armnn::InputLayer>(output->GetInputSlot(0), 0, "input");
81 
82  graph.EraseLayer(output);
83 
84  erasedLayerNamesObservable.Clear();
85 
86  // Check the observable has observed the changes
87  std::list<std::string> emptyList({});
88 
89  BOOST_CHECK_EQUAL_COLLECTIONS(erasedLayerNamesObservable.begin(), erasedLayerNamesObservable.end(),
90  emptyList.begin(), emptyList.end());
91 }
LayerT * AddLayer(Args &&... args)
Adds a new layer, of type LayerType, to the graph constructed with the arguments passed.
Definition: Graph.hpp:402
void EraseLayer(Iterator pos)
Deletes the layer at the specified position.
Definition: Graph.hpp:449
A layer user-provided data can be bound to (e.g. inputs, outputs).
Definition: OutputLayer.hpp:13
A layer user-provided data can be bound to (e.g. inputs, outputs).
Definition: InputLayer.hpp:13
LayerT * InsertNewLayer(InputSlot &insertBefore, Args &&... args)
Inserts a new layer between the output slot currently connected to insertBefore and insertBefore itse...
Definition: Graph.hpp:416