-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1063 from trcrsired/master
[forward_list] add deepseek generated fuzzing test for forward_list sort
- Loading branch information
Showing
2 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |