Welcome to mirror list, hosted at ThFree Co, Russian Federation.

BLI_disjoint_set_test.cc « tests « blenlib « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 92b0915e162766933523a754bf9bb409d3a26c65 (plain)
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
/* SPDX-License-Identifier: Apache-2.0 */

#include "BLI_disjoint_set.hh"
#include "BLI_strict_flags.h"

#include "testing/testing.h"

namespace blender::tests {

TEST(disjoint_set, Test)
{
  DisjointSet disjoint_set(6);
  EXPECT_FALSE(disjoint_set.in_same_set(1, 2));
  EXPECT_FALSE(disjoint_set.in_same_set(5, 3));
  EXPECT_TRUE(disjoint_set.in_same_set(2, 2));
  EXPECT_EQ(disjoint_set.find_root(3), 3);

  disjoint_set.join(1, 2);

  EXPECT_TRUE(disjoint_set.in_same_set(1, 2));
  EXPECT_FALSE(disjoint_set.in_same_set(0, 1));

  disjoint_set.join(3, 4);

  EXPECT_FALSE(disjoint_set.in_same_set(2, 3));
  EXPECT_TRUE(disjoint_set.in_same_set(3, 4));

  disjoint_set.join(1, 4);

  EXPECT_TRUE(disjoint_set.in_same_set(1, 4));
  EXPECT_TRUE(disjoint_set.in_same_set(1, 3));
  EXPECT_TRUE(disjoint_set.in_same_set(2, 4));
  EXPECT_FALSE(disjoint_set.in_same_set(0, 4));
}

}  // namespace blender::tests