Pārlūkot izejas kodu

test: add unit tests for the Array class.

legacy
Sam Hocevar sam pirms 12 gadiem
vecāks
revīzija
c9520d2aca
3 mainītis faili ar 77 papildinājumiem un 1 dzēšanām
  1. +2
    -1
      test/Makefile.am
  2. +74
    -0
      test/unit/array.cpp
  3. +1
    -0
      win32/testsuite.vcxproj

+ 2
- 1
test/Makefile.am Parādīt failu

@@ -23,7 +23,8 @@ TESTS = testsuite

testsuite_SOURCES = testsuite.cpp \
unit/vector.cpp unit/matrix.cpp unit/half.cpp unit/trig.cpp \
unit/build.cpp unit/real.cpp unit/image.cpp unit/quat.cpp unit/cmplx.cpp
unit/build.cpp unit/real.cpp unit/image.cpp unit/quat.cpp unit/cmplx.cpp \
unit/array.cpp
testsuite_CPPFLAGS = @LOL_CFLAGS@ @PIPI_CFLAGS@
testsuite_LDFLAGS = $(top_builddir)/src/liblol.a @LOL_LIBS@ @PIPI_LIBS@
testsuite_DEPENDENCIES = $(top_builddir)/src/liblol.a


+ 74
- 0
test/unit/array.cpp Parādīt failu

@@ -0,0 +1,74 @@
//
// Lol Engine
//
// Copyright: (c) 2010-2012 Sam Hocevar <sam@hocevar.net>
// This program is free software; you can redistribute it and/or
// modify it under the terms of the Do What The Fuck You Want To
// Public License, Version 2, as published by Sam Hocevar. See
// http://sam.zoy.org/projects/COPYING.WTFPL for more details.
//

#if defined HAVE_CONFIG_H
# include "config.h"
#endif

#include "core.h"
#include "lol/unit.h"

namespace lol
{

LOLUNIT_FIXTURE(ArrayTest)
{
void SetUp() {}

void TearDown() {}

LOLUNIT_TEST(ArrayFill)
{
Array<int> a;
a.Append(0);
a.Append(1);
a.Append(2);
a.Append(3);

LOLUNIT_ASSERT_EQUAL(a[0], 0);
LOLUNIT_ASSERT_EQUAL(a[1], 1);
LOLUNIT_ASSERT_EQUAL(a[2], 2);
LOLUNIT_ASSERT_EQUAL(a[3], 3);
}

LOLUNIT_TEST(ArrayCopy)
{
Array<int> a;
a.Append(0);
a.Append(1);
a.Append(2);
a.Append(3);

Array<int> b = a;

LOLUNIT_ASSERT_EQUAL(b[0], 0);
LOLUNIT_ASSERT_EQUAL(b[1], 1);
LOLUNIT_ASSERT_EQUAL(b[2], 2);
LOLUNIT_ASSERT_EQUAL(b[3], 3);
}

LOLUNIT_TEST(EightElements)
{
Array<int, long, float, double, unsigned, char, bool, void *> a;
a.Append(1, 2, 3.f, 4.0, 5, 'a', true, 0);

LOLUNIT_ASSERT_EQUAL(a[0].m1, 1);
LOLUNIT_ASSERT_EQUAL(a[0].m2, 2);
LOLUNIT_ASSERT_EQUAL(a[0].m3, 3.f);
LOLUNIT_ASSERT_EQUAL(a[0].m4, 4.0);
LOLUNIT_ASSERT_EQUAL(a[0].m5, 5);
LOLUNIT_ASSERT_EQUAL(a[0].m6, 'a');
LOLUNIT_ASSERT_EQUAL(a[0].m7, true);
LOLUNIT_ASSERT_EQUAL(a[0].m8, 0);
}
};

} /* namespace lol */


+ 1
- 0
win32/testsuite.vcxproj Parādīt failu

@@ -28,6 +28,7 @@
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\test\testsuite.cpp" />
<ClCompile Include="..\test\unit\array.cpp" />
<ClCompile Include="..\test\unit\build.cpp" />
<ClCompile Include="..\test\unit\cmplx.cpp" />
<ClCompile Include="..\test\unit\half.cpp" />


Notiek ielāde…
Atcelt
Saglabāt