Browse Source

Add a test

Panagiotis Christopoulos Charitos 9 years ago
parent
commit
23ce3fc653
4 changed files with 58 additions and 6 deletions
  1. 0 1
      src/anki/gr/vulkan/DescriptorSet.h
  2. 2 3
      src/anki/util/BitSet.h
  3. 2 2
      tests/util/Atomic.cpp
  4. 54 0
      tests/util/BitSet.cpp

+ 0 - 1
src/anki/gr/vulkan/DescriptorSet.h

@@ -113,7 +113,6 @@ public:
 
 private:
 	VkDescriptorSet m_handle = VK_NULL_HANDLE;
-	DynamicArray<U64> m_resourcesUuids;
 };
 
 /// Creates new descriptor set layouts and descriptor sets.

+ 2 - 3
src/anki/util/BitSet.h

@@ -74,8 +74,7 @@ public:
 		memset(m_chunks, 0, sizeof(m_chunks));
 	}
 
-	/// Flip the bits at the given position. It will go from 1 to 0 or from 0 to
-	/// 1.
+	/// Flip the bits at the given position. It will go from 1 to 0 or from 0 to 1.
 	template<typename TInt>
 	void flip(TInt pos)
 	{
@@ -119,7 +118,7 @@ protected:
 	static const U CHUNK_COUNT = (N + (CHUNK_BIT_COUNT - 1)) / CHUNK_BIT_COUNT;
 
 	/// A mask for some stuff.
-	static const ChunkType MASK = 1 << (CHUNK_BIT_COUNT - 1);
+	static const ChunkType MASK = ChunkType(1) << (CHUNK_BIT_COUNT - 1);
 
 	ChunkType m_chunks[CHUNK_COUNT];
 

+ 2 - 2
tests/util/Atomic.cpp

@@ -3,8 +3,8 @@
 // Code licensed under the BSD License.
 // http://www.anki3d.org/LICENSE
 
-#include "tests/framework/Framework.h"
-#include "anki/util/Atomic.h"
+#include <tests/framework/Framework.h>
+#include <anki/util/Atomic.h>
 
 ANKI_TEST(Util, Atomic)
 {

+ 54 - 0
tests/util/BitSet.cpp

@@ -0,0 +1,54 @@
+// Copyright (C) 2009-2016, Panagiotis Christopoulos Charitos and contributors.
+// All rights reserved.
+// Code licensed under the BSD License.
+// http://www.anki3d.org/LICENSE
+
+#include <tests/framework/Framework.h>
+#include <anki/util/BitSet.h>
+
+ANKI_TEST(Util, BitSet)
+{
+	{
+		BitSet<4, U8> a = {false};
+		ANKI_TEST_EXPECT_EQ(a.get(3), false);
+		a.set(3);
+		ANKI_TEST_EXPECT_EQ(a.get(3), true);
+	}
+
+	{
+		BitSet<9, U8> a = {true};
+		ANKI_TEST_EXPECT_EQ(a.get(8), true);
+		a.set(8, false);
+		ANKI_TEST_EXPECT_EQ(a.get(8), false);
+	}
+
+	{
+		BitSet<4, U64> a = {true};
+		ANKI_TEST_EXPECT_EQ(a.get(3), true);
+		a.set(3, false);
+		ANKI_TEST_EXPECT_EQ(a.get(3), false);
+	}
+
+	{
+		const U N = 120;
+		BitSet<N, U64> a = {false};
+
+		for(U i = 0; i < 1000; ++i)
+		{
+			U r = rand() % N;
+			ANKI_TEST_EXPECT_EQ(a.get(r), false);
+			a.set(r, true);
+			ANKI_TEST_EXPECT_EQ(a.get(r), true);
+
+			for(U n = 0; n < N; ++n)
+			{
+				if(n != r)
+				{
+					ANKI_TEST_EXPECT_EQ(a.get(n), false);
+				}
+			}
+
+			a.set(r, false);
+		}
+	}
+}