yum-mirror/slang

Making it easier to work with shaders

git clone https://git.yummers.dev/yum-mirror/slang

Ellie HermaszewskaCorrect include dir for libslang (#5539)7b570feed

master
2.8 KiB80 linesraw
1// unit-test-path.cpp
2
3#include "core/slang-basic.h"
4#include "unit-test/slang-unit-test.h"
5
6using namespace Slang;
7
8template<typename T>
9static bool _checkArrayView(ArrayView<T> v0, ArrayView<T> v1)
10{
11    if (v0.getCount() != v1.getCount())
12        return false;
13    for (Index i = 0; i < v0.getCount(); i++)
14        if (v0[i] != v1[i])
15            return false;
16    return true;
17}
18
19SLANG_UNIT_TEST(shortList)
20{
21    {
22        ShortList<String, 4> shortList = {"a", "b", "c"};
23        shortList.add("d");
24        auto arrayView = shortList.getArrayView();
25        SLANG_CHECK(arrayView.ownsStorage == false);
26        SLANG_CHECK(
27            _checkArrayView(arrayView.arrayView, List<String>{"a", "b", "c", "d"}.getArrayView()));
28        shortList.add("e");
29        auto arrayView2 = shortList.getArrayView();
30        SLANG_CHECK(arrayView2.ownsStorage == true);
31        SLANG_CHECK(_checkArrayView(
32            arrayView2.arrayView,
33            List<String>{"a", "b", "c", "d", "e"}.getArrayView()));
34        auto arrayView3 = shortList.getArrayView(0, 2);
35        SLANG_CHECK(arrayView3.ownsStorage == false);
36        SLANG_CHECK(_checkArrayView(arrayView3.arrayView, List<String>{"a", "b"}.getArrayView()));
37        auto arrayView4 = shortList.getArrayView(4, 1);
38        SLANG_CHECK(arrayView4.ownsStorage == false);
39        SLANG_CHECK(_checkArrayView(arrayView4.arrayView, List<String>{"e"}.getArrayView()));
40        auto arrayView5 = shortList.getArrayView(2, 3);
41        SLANG_CHECK(arrayView5.ownsStorage == true);
42        SLANG_CHECK(
43            _checkArrayView(arrayView5.arrayView, List<String>{"c", "d", "e"}.getArrayView()));
44
45        ShortList<String, 1> copy2;
46        ShortList<String, 2> copy1;
47        copy1 = shortList;
48        for (auto item : copy1)
49            copy2.add(item);
50        SLANG_CHECK(_checkArrayView(
51            copy2.getArrayView().arrayView,
52            List<String>{"a", "b", "c", "d", "e"}.getArrayView()));
53
54        SLANG_CHECK(copy2.indexOf("a") == 0);
55        SLANG_CHECK(copy2.indexOf("e") == 4);
56
57        SLANG_CHECK(copy2.lastIndexOf("a") == 0);
58        SLANG_CHECK(copy2.lastIndexOf("e") == 4);
59
60        copy2.compress();
61        copy2.add("f");
62        copy2.fastRemove("c");
63        copy2.compress();
64        SLANG_CHECK(_checkArrayView(
65            copy2.getArrayView().arrayView,
66            List<String>{"a", "b", "f", "d", "e"}.getArrayView()));
67
68        shortList.removeLast();
69        shortList.removeLast();
70        shortList.compress();
71        SLANG_CHECK(_checkArrayView(
72            shortList.getArrayView().arrayView,
73            List<String>{"a", "b", "c"}.getArrayView()));
74        shortList.add("d");
75        shortList.add("e");
76        SLANG_CHECK(_checkArrayView(
77            shortList.getArrayView().arrayView,
78            List<String>{"a", "b", "c", "d", "e"}.getArrayView()));
79    }
80}