/**************************************************************************/1/* test_vset.h */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#pragma once3132#include "core/templates/vset.h"3334#include "tests/test_macros.h"3536namespace TestVSet {3738template <typename T>39class TestClass : public VSet<T> {40public:41int _find(const T &p_val, bool &r_exact) const {42return VSet<T>::_find(p_val, r_exact);43}44};4546TEST_CASE("[VSet] _find and _find_exact correctness.") {47TestClass<int> set;4849// insert some values50set.insert(10);51set.insert(20);52set.insert(30);53set.insert(40);54set.insert(50);5556// data should be sorted57CHECK(set.size() == 5);58CHECK(set[0] == 10);59CHECK(set[1] == 20);60CHECK(set[2] == 30);61CHECK(set[3] == 40);62CHECK(set[4] == 50);6364// _find_exact return exact position for existing elements65CHECK(set.find(10) == 0);66CHECK(set.find(30) == 2);67CHECK(set.find(50) == 4);6869// _find_exact return -1 for non-existing elements70CHECK(set.find(15) == -1);71CHECK(set.find(0) == -1);72CHECK(set.find(60) == -1);7374// test _find75bool exact;7677// existing elements78CHECK(set._find(10, exact) == 0);79CHECK(exact == true);8081CHECK(set._find(30, exact) == 2);82CHECK(exact == true);8384// non-existing elements85CHECK(set._find(25, exact) == 2);86CHECK(exact == false);8788CHECK(set._find(35, exact) == 3);89CHECK(exact == false);9091CHECK(set._find(5, exact) == 0);92CHECK(exact == false);9394CHECK(set._find(60, exact) == 5);95CHECK(exact == false);96}9798} // namespace TestVSet99100101