-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalgorithm_test.cc
133 lines (112 loc) · 4.38 KB
/
algorithm_test.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
// Copyright 2024 The Google Research Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "algorithm.h"
#include <cmath>
#include <functional>
#include <iostream>
#include <memory>
#include <ostream>
#include <vector>
#include "task.h"
#include "task_util.h"
#include "definitions.h"
#include "executor.h"
#include "generator_test_util.h"
#include "memory.h"
#include "random_generator.h"
#include "test_util.h"
#include "gtest/gtest.h"
namespace automl_zero {
namespace {
using ::std::make_shared; // NOLINT
TEST(AlgorithmTest, DefaultConstructionProducesCorrectComponentFunctionSizes) {
Algorithm algorithm;
EXPECT_EQ(algorithm.setup_.size(), 0);
EXPECT_EQ(algorithm.predict_.size(), 0);
EXPECT_EQ(algorithm.learn_.size(), 0);
}
TEST(AlgorithmTest, CopyConstructor) {
Algorithm algorithm = SimpleRandomAlgorithm();
Algorithm algorithm_copy = algorithm;
EXPECT_TRUE(algorithm_copy == algorithm);
}
TEST(AlgorithmTest, CopyAssignmentOperator) {
Algorithm algorithm = SimpleRandomAlgorithm();
Algorithm algorithm_copy;
algorithm_copy = algorithm;
EXPECT_TRUE(algorithm_copy == algorithm);
}
TEST(AlgorithmTest, MoveConstructor) {
Algorithm algorithm = SimpleRandomAlgorithm();
Algorithm algorithm_copy = algorithm;
Algorithm algorithm_move = std::move(algorithm);
EXPECT_TRUE(algorithm_move == algorithm_copy);
}
TEST(AlgorithmTest, MoveAssignmentOperator) {
Algorithm algorithm = SimpleRandomAlgorithm();
Algorithm algorithm_copy = algorithm;
Algorithm algorithm_move;
algorithm_move = std::move(algorithm);
EXPECT_TRUE(algorithm_move == algorithm_copy);
}
TEST(AlgorithmTest, CopyAssignmentOperator_SelfCopy) {
Algorithm algorithm = SimpleRandomAlgorithm();
Algorithm algorithm_copy = algorithm;
algorithm_copy = algorithm_copy;
EXPECT_TRUE(algorithm_copy == algorithm);
}
TEST(AlgorithmTest, EqualsOperator) {
Algorithm algorithm = SimpleNoOpAlgorithm();
algorithm.predict_[1] =
make_shared<const Instruction>(VECTOR_SUM_OP, 1, 2, 3);
Algorithm algorithm_same = SimpleNoOpAlgorithm();
algorithm_same.predict_[1] =
make_shared<const Instruction>(VECTOR_SUM_OP, 1, 2, 3);
Algorithm algorithm_different_instruction = SimpleNoOpAlgorithm();
algorithm_different_instruction.predict_[1] =
make_shared<const Instruction>(VECTOR_SUM_OP, 1, 1, 3);
Algorithm algorithm_different_position = SimpleNoOpAlgorithm();
algorithm_different_position.predict_[0] =
make_shared<const Instruction>(VECTOR_SUM_OP, 1, 2, 3);
Algorithm algorithm_different_component_function = SimpleNoOpAlgorithm();
algorithm_different_component_function.learn_[0] =
make_shared<const Instruction>(VECTOR_SUM_OP, 1, 2, 3);
EXPECT_TRUE(algorithm == algorithm_same);
EXPECT_FALSE(algorithm != algorithm_same);
EXPECT_FALSE(algorithm == algorithm_different_instruction);
EXPECT_TRUE(algorithm != algorithm_different_instruction);
EXPECT_FALSE(algorithm == algorithm_different_position);
EXPECT_TRUE(algorithm != algorithm_different_position);
EXPECT_FALSE(algorithm == algorithm_different_component_function);
EXPECT_TRUE(algorithm != algorithm_different_component_function);
Algorithm random_algorithm = SimpleRandomAlgorithm();
Algorithm same_random_algorithm = random_algorithm;
EXPECT_TRUE(random_algorithm == same_random_algorithm);
EXPECT_FALSE(random_algorithm != same_random_algorithm);
}
TEST(AlgorithmTest, ToFromProto) {
Algorithm algorithm_src = SimpleRandomAlgorithm();
Algorithm algorithm_dest;
algorithm_dest = SimpleNoOpAlgorithm();
algorithm_dest.FromProto(algorithm_src.ToProto());
EXPECT_TRUE(algorithm_dest == algorithm_src);
}
TEST(AlgorithmTest, ToFromProtoIntoDifferentComponentFunctionSizes) {
Algorithm algorithm_src = SimpleRandomAlgorithm();
Algorithm algorithm_dest;
algorithm_dest.FromProto(algorithm_src.ToProto());
EXPECT_TRUE(algorithm_dest == algorithm_src);
}
} // namespace
} // namespace automl_zero