MCPcopy Create free account
hub / github.com/apache/tvm-ffi / TEST

Function TEST

tests/cpp/test_tuple.cc:32–68  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

30using namespace tvm::ffi::testing;
31
32TEST(Tuple, Basic) {
33 Tuple<int, float> tuple0(1, 2.0f);
34 EXPECT_EQ(tuple0.get<0>(), 1);
35 EXPECT_EQ(tuple0.get<1>(), 2.0f);
36
37 Tuple<int, float> tuple1 = tuple0;
38 EXPECT_EQ(tuple0.use_count(), 2);
39
40 // test copy on write
41 tuple1.Set<0>(3);
42 EXPECT_EQ(tuple0.get<0>(), 1);
43 EXPECT_EQ(tuple1.get<0>(), 3);
44
45 EXPECT_EQ(tuple0.use_count(), 1);
46 EXPECT_EQ(tuple1.use_count(), 1);
47
48 // copy on write not triggered because
49 // tuple1 is unique.
50 tuple1.Set<1>(4);
51 EXPECT_EQ(tuple1.get<1>(), 4.0f);
52 EXPECT_EQ(tuple1.use_count(), 1);
53
54 // default state
55 Tuple<int, float> tuple2;
56 EXPECT_EQ(tuple2.use_count(), 1);
57 tuple2.Set<0>(1);
58 tuple2.Set<1>(2.0f);
59 EXPECT_EQ(tuple2.get<0>(), 1);
60 EXPECT_EQ(tuple2.get<1>(), 2.0f);
61
62 // tuple of object and primitive
63 Tuple<TInt, int> tuple3(1, 2);
64 EXPECT_EQ(tuple3.get<0>()->value, 1);
65 EXPECT_EQ(tuple3.get<1>(), 2);
66 tuple3.Set<0>(4);
67 EXPECT_EQ(tuple3.get<0>()->value, 4);
68}
69
70TEST(Tuple, AnyConvert) {
71 Tuple<int, TInt> tuple0(1, 2);

Callers

nothing calls this directly

Calls 10

definedMethod · 0.80
use_countMethod · 0.45
valueMethod · 0.45
sizeMethod · 0.45
same_asMethod · 0.45
kindMethod · 0.45
messageMethod · 0.45
insertMethod · 0.45
endMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected