Chromium Code Reviews| Index: components/rappor/byte_vector_utils_unittest.cc |
| diff --git a/components/rappor/byte_vector_utils_unittest.cc b/components/rappor/byte_vector_utils_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..1aa92a3230131b365ccadba06466c6dceac69d25 |
| --- /dev/null |
| +++ b/components/rappor/byte_vector_utils_unittest.cc |
| @@ -0,0 +1,58 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "components/rappor/byte_vector_utils.h" |
| + |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +namespace rappor { |
| + |
| +TEST(ByteVectorTest, TestOr) { |
| + ByteVector lhs(2); |
| + lhs[1] = 0x12; |
| + ByteVector rhs(2); |
| + rhs[1] = 0x03; |
| + |
| + ASSERT_EQ(0x13, (*ByteVectorOr(lhs, &rhs))[1]); |
| +} |
| + |
| +TEST(ByteVectorTest, TestAnd) { |
| + ByteVector lhs(2); |
| + lhs[1] = 0x12; |
| + ByteVector rhs(2); |
| + rhs[1] = 0x03; |
| + |
| + ASSERT_EQ(0x02, (*ByteVectorAnd(lhs, &rhs))[1]); |
| +} |
| + |
| +TEST(ByteVectorTest, TestMerge) { |
| + ByteVector lhs(2); |
| + lhs[1] = 0x33; |
| + ByteVector rhs(2); |
| + rhs[1] = 0x55; |
| + ByteVector mask(2); |
| + mask[1] = 0x0f; |
| + |
| + ASSERT_EQ(0x35, (*ByteVectorMerge(mask, lhs, &rhs))[1]); |
| +} |
| + |
| +TEST(ByteVectorTest, TestGenerator) { |
| + ByteVectorGenerator generator(2); |
| + ByteVector random_50 = generator.GetWeightedRandomByteVector(PROBABILITY_50); |
| + ASSERT_EQ(random_50.size(), 2u); |
| + ByteVector random_75 = generator.GetWeightedRandomByteVector(PROBABILITY_75); |
| + 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.
|
| +} |
| + |
| +TEST(ByteVectorTest, TestHmacGenerator) { |
| + HmacByteVectorGenerator generator(2, "MySecret"); |
| + ByteVector random_50 = generator.GetWeightedRandomByteVector(PROBABILITY_50); |
| + ASSERT_EQ(random_50.size(), 2u); |
| + ASSERT_EQ(random_50[0], 0x16); |
| + ByteVector random_75 = generator.GetWeightedRandomByteVector(PROBABILITY_75); |
| + ASSERT_EQ(random_75.size(), 2u); |
| + ASSERT_EQ(random_75[0], 0xef); |
| +} |
| + |
| +} // namespace rappor |