Procházet zdrojové kódy

Fixed some previously unnoticed bugs

devel
Ludovic 'Archivist' Lagouardette před 4 roky
rodič
revize
cb2dfecc60
7 změnil soubory, kde provedl 178 přidání a 12 odebrání
  1. +5
    -4
      include/gp/algorithm/move.hpp
  2. +1
    -1
      include/gp/array.hpp
  3. +1
    -1
      include/gp/buffer.hpp
  4. +1
    -0
      include/gp/quotient_filter.hpp
  5. +3
    -3
      tests.cpp
  6. +100
    -2
      tests/gp_test.cpp
  7. +67
    -1
      tests/quotient_filter.cpp

+ 5
- 4
include/gp/algorithm/move.hpp Zobrazit soubor

@ -58,11 +58,12 @@ namespace gp{
return nameless_range<typename range_out::associated_iterator>{out, dest.end()};
}
template<typename T, typename range_in, typename range_out>
nameless_range<typename range_out::associated_iterator> move_uninitialized(range_in src, range_out dest)
template<typename range_in, typename range_out>
nameless_range<typename gp::remove_reference<range_out>::type::associated_iterator> move_uninitialized(range_in&& src, range_out&& dest)
{
using T = typename gp::remove_reference<decltype(*dest.begin())>::type;
if(src.size()>dest.size())
return nameless_range<typename range_out::associated_iterator>(dest.begin(), dest.end());
return nameless_range<typename gp::remove_reference<range_out>::type::associated_iterator>(dest.begin(), dest.end());
auto in = src.begin();
auto in_close = src.end();
auto out = dest.begin();
@ -70,6 +71,6 @@ namespace gp{
{
new(&*(out++)) T{gp::move(*(in++))};
}
return nameless_range<typename range_out::associated_iterator>{out, dest.end()};
return nameless_range<typename gp::remove_reference<range_out>::type::associated_iterator>{out, dest.end()};
}
}

+ 1
- 1
include/gp/array.hpp Zobrazit soubor

@ -33,7 +33,7 @@ namespace gp{
array(array&& values)
{
gp::move_uninitializedo"><T>(
gp::move_uninitialized(
values,
*this
);

+ 1
- 1
include/gp/buffer.hpp Zobrazit soubor

@ -81,7 +81,7 @@ namespace gp{
}
else
{
if(size()*sizeof(T)o">/sizeof(U))
if(p">(size()*sizeof(T)p">)%sizeof(U) == 0)
{
return buffer<U>(reinterpret_cast<U*>(&*begin_elem), size()*sizeof(T)/sizeof(U));
}

+ 1
- 0
include/gp/quotient_filter.hpp Zobrazit soubor

@ -193,6 +193,7 @@ namespace gp {
if(slot.r == r)
{
slot.is_deleted = true;
slot.is_occupied = false;
}
}
skip.next();

+ 3
- 3
tests.cpp Zobrazit soubor

@ -18,13 +18,13 @@ int main()
{
++runned;
int value;
k">try{
cm">/*try{*/
value = test->run();
if(value)
{
std::cout << std::dec << test->name << " failed with "<< value << std::endl;
}
p">} catch (gp::runtime_error err) {
cm">/*} catch (gp::runtime_error err) {
std::cout << test->name << " failed with an exception: " << err.what() << std::endl;
value = -1;
} catch (gp_config::assert_failure err) {
@ -33,7 +33,7 @@ int main()
} catch (...) {
std::cout << test->name << " failed with an exception" << std::endl;
value = -1;
}
}*/
failed += (value != 0);
}
std::cout << std::dec << "Runned "<<runned<<" tests with "<<failed<<" failures" << std::endl;

+ 100
- 2
tests/gp_test.cpp Zobrazit soubor

@ -8,6 +8,7 @@
#include "gp/allocator/dummy.hpp"
#include "gp/algorithm/repeat.hpp"
#include "gp/algorithm/rotate.hpp"
#include "gp/algorithm/move.hpp"
#include "gp/ring_list.hpp"
#include <thread>
#include <chrono>
@ -553,11 +554,108 @@ struct indexed_array_test : public test_scaffold {
{
// TODO: write a concrete implementation and test it
// gp::vfs fs;
}
}
return res;
}
};
append_test dummy_khxurgsd3(new indexed_array_test{});
append_test dummy_khxurgsd3(new indexed_array_test{});
struct move_uninitialized_test : public test_scaffold {
move_uninitialized_test() {
name = __FILE__ ":8";
}
struct tester {
size_t* const incremented;
tester(size_t* ptr)
: incremented(ptr)
{}
tester(tester&& oth)
: incremented(oth.incremented)
{
++*incremented;
}
};
virtual int run() {
int res = 0;
{
size_t counter;
using src_t = gp::array<tester, 16>;
src_t *source = reinterpret_cast<src_t*>(malloc(sizeof(src_t)));
gp::array<char, sizeof(tester)*16> buffer;
for(auto& a : *source) {
new(&a) tester(&counter);
}
gp::move_uninitialized(*source, buffer.as_buffer().cast<tester>());
free(source);
}
return res;
}
};
append_test dummy_hkfyr5f5(new move_uninitialized_test{});
struct clamp_test : public test_scaffold {
clamp_test() {
name = __FILE__ ":9";
}
virtual int run() {
int res = 0;
{
res += gp::clamp<float>(0.0, -1.0, 1.0);
res += gp::clamp<float>(-1.0, 1.0, 0.0);
res += gp::max(-1, -2, 0, -3);
}
return res;
}
};
append_test dummy_gsdh25f5(new clamp_test{});
struct buffer_test : public test_scaffold {
buffer_test() {
name = __FILE__ ":10";
}
virtual int run() {
int res = 0;
{
gp::array<char, 24> data;
gp::array<char, 24> data_e;
gp::buffer<char> handle = data.as_buffer();
handle[12] = '&';
gp_config::assertion(*(handle.begin()+12) == '&', "Could not assign to the buffer");
res += 1;
try {
handle[24] = 16;
res += 1;
handle[-1] = 16;
res += 1;
handle[1024] = 16;
} catch (...) {
res -= 1;
}
res += 1;
try {
auto cast = handle.cast<gp::array<char, 32>>();
} catch (...) {
res -= 1;
}
auto cast = handle.template cast<gp::array<char, 6>>().template cast<gp::array<char, 4>>();
gp_config::assertion(false == (data == data_e), "Different arrays should return false here");
}
return res;
}
};
append_test dummy_gs87ytf5f5(new buffer_test{});

+ 67
- 1
tests/quotient_filter.cpp Zobrazit soubor

@ -124,4 +124,70 @@ struct qfilter3_test : public test_scaffold {
}
};
append_test dummy_kjdflu3(new qfilter3_test{});
append_test dummy_kjdflu3(new qfilter3_test{});
struct qfilter4_test : public test_scaffold {
qfilter4_test() {
}
virtual int run() {
gp::quotient_filter<> test_filter;
for(int a = 0 ; a < 10000; a++)
{
test_filter.set_hash(a);
}
for(int a = 0 ; a < 10000; a++)
{
test_filter.remove_hash(a);
}
for(int a = 0 ; a < 10000; a++)
{
gp_config::assertion(!test_filter.test_hash(a), "everything should have been removed");
}
for(int a = 0 ; a < 10000; a++)
{
test_filter.set_hash(a);
}
for(int a = 0 ; a < 10000; a++)
{
gp_config::assertion(test_filter.test_hash(a), "everything should have been set");
}
return 0;
}
};
append_test dummy_kj54ghu3(new qfilter4_test{});
struct qfilter5_test : public test_scaffold {
qfilter5_test() {
}
virtual int run() {
gp::quotient_filter<uint32_t, 16> test_filter;
for(int a = 0 ; a < 65536; a++)
{
test_filter.set_hash(a);
}
int res = 1;
try {
test_filter.set_hash(123456);
} catch(gp::runtime_error e) {
res = 0;
}
return res;
}
};
append_test dummy_k65421u3(new qfilter5_test{});

Načítá se…
Zrušit
Uložit