1 /*
2 * Copyright (c) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <random>
17
18 #include <gtest/gtest.h>
19 #include "util/graph_check.h"
20 #include "../common.h"
21
22 using namespace std;
23 using namespace testing;
24 #ifdef HWTEST_TESTING_EXT_ENABLE
25 using namespace testing::ext;
26 #endif
27 using namespace ffrt;
28
29 class GraphCheckTest : public testing::Test {
30 protected:
SetUpTestCase()31 static void SetUpTestCase()
32 {
33 }
34
TearDownTestCase()35 static void TearDownTestCase()
36 {
37 }
38
SetUp()39 virtual void SetUp()
40 {
41 }
42
TearDown()43 virtual void TearDown()
44 {
45 }
46 };
47
HWTEST_F(GraphCheckTest, HasCyclic, TestSize.Level1)48 HWTEST_F(GraphCheckTest, HasCyclic, TestSize.Level1)
49 {
50 GraphCheckCyclic graph;
51
52 graph.AddVetexByLabel(0x12);
53 graph.AddVetexByLabel(0x34);
54 graph.AddEdgeByLabel(0x12, 0x34);
55 graph.AddEdgeByLabel(0x34, 0x12);
56
57 EXPECT_EQ(graph.VertexNum(), 2);
58 EXPECT_EQ(graph.IsCyclic(), true);
59 }
60
HWTEST_F(GraphCheckTest, HasNoCyclic, TestSize.Level1)61 HWTEST_F(GraphCheckTest, HasNoCyclic, TestSize.Level1)
62 {
63 GraphCheckCyclic graph;
64
65 graph.AddVetexByLabel(0x12);
66 graph.AddVetexByLabel(0x34);
67 graph.AddEdgeByLabel(0x12, 0x34);
68 graph.AddEdgeByLabel(0x34, 0x12);
69 graph.RemoveEdgeByLabel(0x12);
70
71 EXPECT_EQ(graph.EdgeNum(), 1);
72 EXPECT_EQ(graph.IsCyclic(), false);
73 }
74