#include "../collections/BitVector.hpp" #include <stdio.h> #include "gtest_helpers.hpp" #include <gtest/gtest.h> class BitSetTest : public testing::Test { protected: virtual void SetUp() override { bs.Set(0); bs.Set(2); bs.Set(4); bs.Set(6); bs.Set(8); bs.Set(10); bs.Set(12); bs.Set(14); } sprawl::collections::BitSet<16> bs; }; TEST_F(BitSetTest, SetWorks) { EXPECT_TRUE(bs.HasBit(0)); EXPECT_TRUE(bs.HasBit(2)); EXPECT_TRUE(bs.HasBit(4)); EXPECT_TRUE(bs.HasBit(6)); EXPECT_TRUE(bs.HasBit(8)); EXPECT_TRUE(bs.HasBit(10)); EXPECT_TRUE(bs.HasBit(12)); EXPECT_TRUE(bs.HasBit(14)); EXPECT_EQ(size_t(16), bs.Size()); } TEST_F(BitSetTest, CountWorks) { ASSERT_EQ(size_t(8), bs.Count()); } TEST_F(BitSetTest, FlipWorks) { bs.Flip(5); ASSERT_TRUE(bs.HasBit(5)); bs.Flip(5); ASSERT_FALSE(bs.HasBit(5)); } TEST_F(BitSetTest, UnsetWorks) { bs.Unset(2); ASSERT_FALSE(bs.HasBit(2)); } TEST_F(BitSetTest, ToStringWorks) { sprawl::String str = bs.ToString(); ASSERT_EQ(sprawl::String("0101010101010101"), str); } TEST_F(BitSetTest, NoneAllAnyWork) { EXPECT_FALSE(bs.None()); EXPECT_FALSE(bs.All()); EXPECT_TRUE(bs.Any()); bs.Reset(); EXPECT_TRUE(bs.None()); EXPECT_FALSE(bs.All()); EXPECT_FALSE(bs.Any()); for(int i = 0; i < 16; ++i) { bs.Set(i); } EXPECT_FALSE(bs.None()); EXPECT_TRUE(bs.All()); EXPECT_TRUE(bs.Any()); } class BitVectorTest : public testing::Test { protected: virtual void SetUp() override { bv.Set(0); bv.Set(2); bv.Set(4); bv.Set(6); bv.Set(8); bv.Set(10); bv.Set(12); bv.Set(14); } sprawl::collections::BitVector bv; }; TEST_F(BitVectorTest, SetWorks) { EXPECT_TRUE(bv.HasBit(0)); EXPECT_TRUE(bv.HasBit(2)); EXPECT_TRUE(bv.HasBit(4)); EXPECT_TRUE(bv.HasBit(6)); EXPECT_TRUE(bv.HasBit(8)); EXPECT_TRUE(bv.HasBit(10)); EXPECT_TRUE(bv.HasBit(12)); EXPECT_TRUE(bv.HasBit(14)); EXPECT_EQ(size_t(15), bv.Size()); } TEST_F(BitVectorTest, CountWorks) { ASSERT_EQ(size_t(8), bv.Count()); } TEST_F(BitVectorTest, FlipWorks) { bv.Flip(5); ASSERT_TRUE(bv.HasBit(5)); bv.Flip(5); ASSERT_FALSE(bv.HasBit(5)); } TEST_F(BitVectorTest, UnsetWorks) { bv.Unset(2); ASSERT_FALSE(bv.HasBit(2)); } TEST_F(BitVectorTest, ToStringWorks) { sprawl::String str = bv.ToString(); ASSERT_EQ(sprawl::String("101010101010101"), str); } TEST_F(BitVectorTest, NoneAllAnyWork) { EXPECT_FALSE(bv.None()); EXPECT_FALSE(bv.All()); EXPECT_TRUE(bv.Any()); bv.Reset(); EXPECT_TRUE(bv.None()); EXPECT_FALSE(bv.All()); EXPECT_FALSE(bv.Any()); for(int i = 0; i < 16; ++i) { bv.Set(i); } EXPECT_FALSE(bv.None()); EXPECT_TRUE(bv.All()); EXPECT_TRUE(bv.Any()); } TEST_F(BitVectorTest, GrowWorks) { bv.Set(12768); for(int i = 0; i < 16; ++i) { if(i % 2 == 0) { EXPECT_TRUE(bv.HasBit(i)); } else { EXPECT_FALSE(bv.HasBit(i)); } } for(int i = 16; i < 12768; ++i) { EXPECT_FALSE(bv.HasBit(i)); } EXPECT_TRUE(bv.HasBit(12768)); }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 23398 | ququlala | "Forking branch Mainline of shadauxcat-libsprawl to ququlala-libsprawl." | ||
//guest/ShadauxCat/Sprawl/Mainline/UnitTests/UnitTests_BitVector.cpp | |||||
#7 | 16768 | ShadauxCat |
Improvements to error handling in builds with exceptions disabled: - In debug builds or with SPRAWL_ERRORSTATE_STRICT enabled, ErrorState will output a message to stderr and terminate if Get() is called when an error flag is set. (In release buils or with SPRAWL_ERRORSTATE_PERMISSIVE defined, Get() will return junk memory in this case.) - In debug builds or with SPRAWL_ERRORSTATE_STRICT enabled, ErrorState will output a message to stderr and terminate if its destructor is called without checking the errorstate if an error is present (equivalent to an exception terminating the application if no catch() block is present for it). - On linux builds and when running "Analyze" through visual studio, a warning will be issued if any function returning ErrorState has its return value ignored. (This only applies to builds with exceptions not enabled; when exceptions are enabled no warning is issued) - Many functions that could return ErrorState were having their return values silently ignored in internal sprawl code so the user would not find out about errors if exceptions are disabled; now anything in sprawl code that calls a function returning ErrorState will either handle the error, or (in most cases) surface it back up to the user. - As a positive side-effect of the warnings for ignoring ErrorState, several constructors that were capable of throwing exceptions are no longer capable of doing so. #review-16769 |
||
#6 | 14146 | ShadauxCat |
Moving a gtest-specific function out of String.hpp #review-14147 |
||
#5 | 14144 | ShadauxCat |
Switching unit tests to gtest. 100 is a decent number of tests to start with, but it needs to be more like 400 to test the current codebase. #review-14145 |
||
#4 | 14123 | ShadauxCat | Fixed clang warning. | ||
#3 | 14121 | ShadauxCat |
-Fixed msvc compile errors (msvc sucks at decltype, btw...) -Fixed BitVector and BitSet being broken on msvc due to 1L being 32-bit rather than 64-bit -Fixed Deque being broken on 32-bit systems due to an errant int64_t -Changed types of deque indexes from size_t to ssize_t; since they have to be signed for a moment to handle circling the buffer, the sign bit is lost for capacity anyway, and using signed indexes means... -Deque and Vector now support negative indexing a la python list #review-14122 |
||
#2 | 14098 | ShadauxCat |
Added BitVector (BitSet that dynamically increases in size as needed to accommodate the highest bit that gets set). Later I'll add proper operators for both (i.e., BitSet(010101) & BitSet(011011) = BitSet(010001)) #review-14099 |
||
#1 | 14092 | ShadauxCat |
Added BitSet (statically sized at compile time) and corresponding unit test. BitVector (dynamically sized to the largest input it receives) to come next. #review-14093 |