ArmNN
 22.05
ObservableTest.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #include <doctest/doctest.h>
7 
8 #include "Graph.hpp"
9 #include "Observable.hpp"
10 
11 TEST_SUITE("Observable")
12 {
13 TEST_CASE("AddedLayerObservableTest")
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  CHECK(std::equal(layerObservable.begin(), layerObservable.end(),
28  testLayers.begin(), testLayers.end()));
29 }
30 
31 TEST_CASE("ClearAddedLayerObservableTest")
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  CHECK(std::equal(addedLayerObservable.begin(), addedLayerObservable.end(),
48  emptyList.begin(), emptyList.end()));
49 }
50 
51 TEST_CASE("ErasedLayerNamesObservableTest")
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  CHECK(std::equal(erasedLayerNamesObservable.begin(), erasedLayerNamesObservable.end(),
68  testList.begin(), testList.end()));
69 }
70 
71 TEST_CASE("ClearErasedLayerNamesObservableTest")
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  CHECK(std::equal(erasedLayerNamesObservable.begin(), erasedLayerNamesObservable.end(),
90  emptyList.begin(), emptyList.end()));
91 }
92 
93 }
94 
LayerT * AddLayer(Args &&... args)
Adds a new layer, of type LayerType, to the graph constructed with the arguments passed.
Definition: Graph.hpp:425
void EraseLayer(Iterator pos)
Deletes the layer at the specified position.
Definition: Graph.hpp:473
TEST_SUITE("Observable")
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:440