yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
7b570feed
master
1// unit-test-free-list.cpp 2 3#include "../../source/core/slang-free-list.h" 4#include "../../source/core/slang-list.h" 5#include "../../source/core/slang-random-generator.h" 6#include "unit-test/slang-unit-test.h" 7 8#include <stdio.h> 9#include <stdlib.h> 10 11using namespace Slang ; 12 13SLANG_UNIT_TEST (freeList ) 14{ 15FreeList freeList ; 16freeList .init (sizeof (int ),sizeof (void * ),10 ); 17 18DefaultRandomGenerator randGen (0x24343 ); 19 20List < int *> allocs ; 21 22for (int i = 0 ;i < 1000 ;i ++ ) 23 { 24const int numAlloc = randGen .nextInt32UpTo (20 ); 25 26for (int j = 0 ;j < numAlloc ;j ++ ) 27 { 28int * ptr = (int * )freeList .allocate (); 29* ptr = i ; 30allocs .add (ptr ); 31 } 32 33int numDealloc = randGen .nextInt32UpTo (19 ); 34numDealloc = int (allocs .getCount ())< numDealloc ?int (allocs .getCount ()) :numDealloc ; 35 36for (int j = 0 ;j < numDealloc ;j ++ ) 37 { 38const int index = randGen .nextInt32UpTo (int (allocs .getCount ())); 39 40int * alloc = allocs [index ]; 41 42SLANG_CHECK (* alloc <=i ); 43SLANG_CHECK (* alloc >=0 ); 44 45freeList .deallocate (alloc ); 46 47allocs .fastRemoveAt (index ); 48 } 49 } 50}