<commit_before>#include "../TestCase.hpp"

WRD_TEST_START(ChunkTest)
	//	Basic test:
	Chunk chk(4, true);
	//		MemoryHaver:
	T(chk.getLen() == 0)
	T(chk.getSize() == 0)
	T(chk[0] == chk.get(0))
	T( ! chk[1])
	T( ! chk[-1])
	T(chk.isFull())
	T( ! chk.isCapable())
	T( ! chk.has(*(Instance*) NULL))
	//		Allocator:
	T(chk.getBlkSize() == 4)
	T( ! chk.release())
	T(chk.getLen() == 0)
	T(chk.getSize() == 0)
	T( ! chk.getEOB())
	T( ! chk.getHeap())

	//		Chunk:
	class Heap {
	public:
		void new1(Chunk& chk, wcnt cnt) {
			for(int n=0; n < cnt ; n++)
				ptrs.push_back(chk.new1());
		}
		void del(Chunk& chk) {
			for(void* e : ptrs)
				chk.del(e, chk.getBlkSize());
			ptrs.clear();
		}
		std::vector<void*> ptrs;
	};
	Heap heap;
	T(chk.isFixed())
	heap.new1(chk, 1);
	T(chk.getLen() == 1)
	T(chk.getSize() >= 1)
	T(chk[0])
	T(chk[0] == heap.ptrs[0])
	T( ! chk[-1])
	T(chk.getEOB())
	T(chk.getHeap())

	heap.new1(chk, 1);
	T(chk.getLen() == 2)
	T(chk.getSize() >= chk.getLen())
	T(chk[1])
	T(chk.has(*(Instance*)chk[1]))
	T( chk.getBlkSize() == 4)

	heap.del(chk);
	T(chk.getLen() == 0)
	T(chk.getSize() >= 2)
	T( ! chk[0])
	T(chk.getHeap())
	T(  chk.getBlkSize() == 4)

	T(chk.release())
	T(chk.getSize() == 0)
	T( ! chk.getHeap())
	T(   chk.getBlkSize() == 4)
	T(chk.isFixed())

	T( ! chk.resize(5))
	T(chk.getSize() == 5)
	T(chk.getLen() == 0)
	T(chk[4] == chk[0])
	T(chk[0] == chk[-1])
	T(chk[-1] == NULL)
	T(chk.getHeap())
	T(chk.getEOB())
	T( ! chk.isFull())
	T(chk.isCapable())

	heap.new1(chk, 10);
	heap.del(chk);
	T( ! chk.getLen())

	heap.new1(chk, 100);
	heap.del(chk);
	T( ! chk.getLen())

	heap.new1(chk, 1000);
	heap.del(chk);
	T( ! chk.getLen())

	heap.new1(chk, 10000);
	heap.del(chk);
	T( ! chk.getLen())

	heap.new1(chk, 100000);<commit_msg>- [ut] ChunkTest has defects on its scenario.<commit_after>#include "../TestCase.hpp"

WRD_TEST_START(ChunkTest)
	//	Basic test:
	Chunk chk(4, false);
	//		MemoryHaver:
	T(chk.getLen() == 0)
	T(chk.getSize() == 0)
	T(chk[0] == chk.get(0))
	T( ! chk[1])
	T( ! chk[-1])
	T(chk.isFull())
	T( ! chk.isCapable())
	T( ! chk.has(*(Instance*) NULL))
	//		Allocator:
	T(chk.getBlkSize() == 4)
	T( ! chk.release())
	T(chk.getLen() == 0)
	T(chk.getSize() == 0)
	T( ! chk.getEOB())
	T( ! chk.getHeap())

	//		Chunk:
	class Heap {
	public:
		void new1(Chunk& chk, wcnt cnt) {
			for(int n=0; n < cnt ; n++)
				ptrs.push_back(chk.new1());
		}
		void del(Chunk& chk) {
			for(void* e : ptrs)
				chk.del(e, chk.getBlkSize());
			ptrs.clear();
		}
		std::vector<void*> ptrs;
	};
	Heap heap;
	T( ! chk.isFixed())
	heap.new1(chk, 1);
	T(chk.getLen() == 1)
	T(chk.getSize() == Chunk::INIT_SZ)
	T(chk[0])
	T(chk[0] == heap.ptrs[0])
	T( ! chk[-1])
	T(chk.getEOB())
	T(chk.getHeap())

	heap.new1(chk, 1);
	T(chk.getLen() == 2)
	T(chk.getSize() >= chk.getLen())
	T(chk[1])
	T(chk.has(*(Instance*)chk[1]))
	T( chk.getBlkSize() == 4)

	heap.del(chk);
	T(chk.getLen() == 0)
	T(chk.getSize() >= Chunk::INIT_SZ)
	T( ! chk[0])
	T(chk.getHeap())
	T(  chk.getBlkSize() == 4)

	T( ! chk.release())
	T(chk.getSize() == 0)
	T( ! chk.getHeap())
	T(   chk.getBlkSize() == 4)
	T( ! chk.isFixed())

	T( ! chk.resize(5))
	T(chk.getSize() == Chunk::INIT_SZ)
	T( ! chk.resize(Chunk::INIT_SZ+5))
	T(chk.getSize() == Chunk::INIT_SZ+5)
	T(chk.getLen() == 0)
	T(chk[4] == chk[0])
	T(chk[0] == chk[-1])
	T(chk[-1] == NULL)
	T(chk.getHeap())
	T(chk.getEOB())
	T( ! chk.isFull())
	T(chk.isCapable())

	heap.new1(chk, 10);
	heap.del(chk);
	T( ! chk.getLen())

	heap.new1(chk, 100);
	heap.del(chk);
	T( ! chk.getLen())

	heap.new1(chk, 1000);
	heap.del(chk);
	T( ! chk.getLen())

	heap.new1(chk, 10000);
	heap.del(chk);
	T( ! chk.getLen())

	heap.new1(chk, 100000);
{'fraction_non_alphanumeric': 0.262714169159641, 'fraction_numerical': 0.03562686973075877, 'mean_word_length': 3.5407407407407407, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3938414', 'n_tokens_mistral': 2009, 'n_tokens_neox': 1982, 'n_words': 313}