Skip to content

Commit

Permalink
Merge pull request #1063 from trcrsired/master
Browse files Browse the repository at this point in the history
[forward_list] add deepseek generated fuzzing test for forward_list sort
  • Loading branch information
trcrsired authored Feb 1, 2025
2 parents 9bad4fd + 6393c9f commit fffdb08
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 0 deletions.
71 changes: 71 additions & 0 deletions fuzzing/0007.containers/forward_list/sort.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#include <fast_io.h>
#include <fast_io_dsal/forward_list.h>
#include <fast_io_dsal/span.h>
#include <algorithm>
#include <limits>

// This code is generated by DeepSeek, an AI assistant.
// For more information, visit https://www.deepseek.com.

extern "C" int LLVMFuzzerTestOneInput(::std::uint8_t *data, ::std::size_t size)
{
auto first{reinterpret_cast<::std::size_t *>(data)};
auto last{first + size / sizeof(::std::size_t)};
::fast_io::span<::std::size_t> sp(first, last);

// Test empty list
if (sp.empty())
{
::fast_io::forward_list<::std::size_t> flist;
flist.sort();
if (!flist.empty()) [[unlikely]]
{
::fast_io::panic("Empty list should remain empty after sort");
}
return 0;
}

// Test single-element list
if (sp.size() == 1)
{
::fast_io::forward_list<::std::size_t> flist(::std::from_range, sp);
flist.sort();
if (flist.front() != sp.front()) [[unlikely]]
{
::fast_io::panic("Single element list should remain unchanged after sort");
}
return 0;
}

// Test normal list
::fast_io::forward_list<::std::size_t> flist(::std::from_range, sp);
flist.sort();

if (sp.size() != static_cast<::std::size_t>(::std::ranges::distance(flist)) ||
!::std::ranges::is_sorted(flist)) [[unlikely]]
{
::fast_io::panic("flist not sorted:\n", ::fast_io::mnp::rgvw(flist, "\n"));
}

// Test list with duplicate elements
::fast_io::forward_list<::std::size_t> flist_with_duplicates(::std::from_range, sp);
flist_with_duplicates.insert_after(flist_with_duplicates.before_begin(), sp.front());
flist_with_duplicates.sort();
if (!::std::ranges::is_sorted(flist_with_duplicates)) [[unlikely]]
{
::fast_io::panic("flist with duplicates not sorted:\n", ::fast_io::mnp::rgvw(flist_with_duplicates, "\n"));
}

// Test large list
if (sp.size() > 1000)
{
::fast_io::forward_list<::std::size_t> large_flist(::std::from_range, sp);
large_flist.sort();
if (!::std::ranges::is_sorted(large_flist)) [[unlikely]]
{
::fast_io::panic("Large flist not sorted:\n", ::fast_io::mnp::rgvw(large_flist, "\n"));
}
}

return 0;
}
19 changes: 19 additions & 0 deletions fuzzing/0007.containers/list/sort.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include <fast_io.h>
#include <fast_io_dsal/list.h>
#include <fast_io_dsal/span.h>
#include <algorithm>

extern "C" int LLVMFuzzerTestOneInput(::std::uint8_t *data, ::std::size_t size)
{
auto first{reinterpret_cast<::std::size_t*>(data)};
auto last{first+size/sizeof(::std::size_t)};
::fast_io::span<::std::size_t> sp(first,last);
::fast_io::list<::std::size_t> lst(::std::from_range,sp);
lst.sort();
if(sp.size()!=static_cast<::std::size_t>(::std::ranges::distance(lst))||
!::std::ranges::is_sorted(lst)) [[unlikely]]
{
::fast_io::panic("lst not sorted:\n", ::fast_io::mnp::rgvw(lst,"\n"));
}
return 0;
}

0 comments on commit fffdb08

Please sign in to comment.