OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "components/rappor/byte_vector_utils.h" | |
6 | |
7 #include "testing/gtest/include/gtest/gtest.h" | |
8 | |
9 namespace rappor { | |
10 | |
11 TEST(ByteVectorTest, TestOr) { | |
12 ByteVector lhs(2); | |
13 lhs[1] = 0x12; | |
14 ByteVector rhs(2); | |
15 rhs[1] = 0x03; | |
16 | |
17 ASSERT_EQ(0x13, (*ByteVectorOr(lhs, &rhs))[1]); | |
18 } | |
19 | |
20 TEST(ByteVectorTest, TestAnd) { | |
21 ByteVector lhs(2); | |
22 lhs[1] = 0x12; | |
23 ByteVector rhs(2); | |
24 rhs[1] = 0x03; | |
25 | |
26 ASSERT_EQ(0x02, (*ByteVectorAnd(lhs, &rhs))[1]); | |
27 } | |
28 | |
29 TEST(ByteVectorTest, TestMerge) { | |
30 ByteVector lhs(2); | |
31 lhs[1] = 0x33; | |
32 ByteVector rhs(2); | |
33 rhs[1] = 0x55; | |
34 ByteVector mask(2); | |
35 mask[1] = 0x0f; | |
36 | |
37 ASSERT_EQ(0x35, (*ByteVectorMerge(mask, lhs, &rhs))[1]); | |
38 } | |
39 | |
40 TEST(ByteVectorTest, TestGenerator) { | |
41 ByteVectorGenerator generator(2); | |
42 ByteVector random_50 = generator.GetWeightedRandomByteVector(PROBABILITY_50); | |
43 ASSERT_EQ(random_50.size(), 2u); | |
44 ByteVector random_75 = generator.GetWeightedRandomByteVector(PROBABILITY_75); | |
45 ASSERT_EQ(random_75.size(), 2u); | |
Ilya Sherman
2014/01/10 11:00:32
It would be nice to have a statistical test that h
Steven Holte
2014/01/15 04:53:44
Added simple binomial tests.
| |
46 } | |
47 | |
48 TEST(ByteVectorTest, TestHmacGenerator) { | |
49 HmacByteVectorGenerator generator(2, "MySecret"); | |
50 ByteVector random_50 = generator.GetWeightedRandomByteVector(PROBABILITY_50); | |
51 ASSERT_EQ(random_50.size(), 2u); | |
52 ASSERT_EQ(random_50[0], 0x16); | |
53 ByteVector random_75 = generator.GetWeightedRandomByteVector(PROBABILITY_75); | |
54 ASSERT_EQ(random_75.size(), 2u); | |
55 ASSERT_EQ(random_75[0], 0xef); | |
56 } | |
57 | |
58 } // namespace rappor | |
OLD | NEW |