Imported Upstream version 1.7.0
[platform/core/ml/nnfw.git] / compiler / nest / core / src / VarContext.test.cpp
1 /*
2  * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *    http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include "nest/VarContext.h"
18
19 #include <gtest/gtest.h>
20
21 TEST(VAR_CONTEXT, make)
22 {
23   nest::VarContext ctx;
24
25   auto var_0 = ctx.make();
26   auto var_1 = ctx.make();
27
28   ASSERT_FALSE(var_0.id() == var_1.id());
29 }
30
31 TEST(VAR_CONTEXT, count)
32 {
33   nest::VarContext ctx;
34
35   ASSERT_EQ(0, ctx.count());
36
37   auto var_0 = ctx.make();
38
39   ASSERT_EQ(1, ctx.count());
40
41   auto var_1 = ctx.make();
42
43   ASSERT_EQ(2, ctx.count());
44 }
45
46 TEST(VAR_CONTEXT, bound_one)
47 {
48   nest::VarContext ctx;
49
50   auto var_0 = ctx.make();
51
52   ASSERT_EQ(0, ctx.bound(var_0).min());
53   ASSERT_EQ(0, ctx.bound(var_0).max());
54
55   ctx.bound(var_0) = nest::Bound{-3, 5};
56
57   ASSERT_EQ(-3, ctx.bound(var_0).min());
58   ASSERT_EQ(5, ctx.bound(var_0).max());
59 }
60
61 TEST(VAR_CONTEXT, bound_independent)
62 {
63   nest::VarContext ctx;
64
65   auto var_0 = ctx.make();
66
67   ASSERT_EQ(0, ctx.bound(var_0).min());
68   ASSERT_EQ(0, ctx.bound(var_0).max());
69
70   auto var_1 = ctx.make();
71
72   ASSERT_EQ(0, ctx.bound(var_1).min());
73   ASSERT_EQ(0, ctx.bound(var_1).max());
74
75   ctx.bound(var_0) = nest::Bound{-3, 5};
76
77   ASSERT_EQ(-3, ctx.bound(var_0).min());
78   ASSERT_EQ(5, ctx.bound(var_0).max());
79
80   ASSERT_EQ(0, ctx.bound(var_1).min());
81   ASSERT_EQ(0, ctx.bound(var_1).max());
82 }