Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions changelog.d/20260329_move_tests_to_integration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
bump: patch
---

### Changed
- Moved all tests from `src/tests/` to `tests/` folder (integration tests)
- Added 10 new tests for improved code coverage of edge cases and unsafe code paths
3 changes: 0 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ mod link_type;
mod lists;
mod trees;

#[cfg(test)]
mod tests;

pub use link_type::LinkType;
pub use lists::{
AbsoluteCircularLinkedList, AbsoluteLinkedList, LinkedList, RelativeCircularLinkedList,
Expand Down
56 changes: 29 additions & 27 deletions src/tests/mod.rs → tests/common/mod.rs
Original file line number Diff line number Diff line change
@@ -1,34 +1,36 @@
//! Comprehensive tests for 100% code coverage of platform-trees
//! Shared test implementations for integration tests.
//!
//! These test fixtures provide concrete implementations of the library's traits
//! for use in testing. They serve as clear examples of how to implement each trait.

use crate::{
AbsoluteCircularLinkedList, AbsoluteLinkedList, IterativeSizeBalancedTree, LinkType,
LinkedList, RecursiveSizeBalancedTree, RelativeCircularLinkedList, RelativeLinkedList,
};
#![allow(dead_code)]

mod list_tests;
mod tree_tests;
use platform_trees::{
AbsoluteCircularLinkedList, AbsoluteLinkedList, IterativeSizeBalancedTree, LinkedList,
RecursiveSizeBalancedTree, RelativeCircularLinkedList, RelativeLinkedList,
};

// =============================================================================
// Test implementations
// =============================================================================

/// A simple node structure for testing linked lists
#[derive(Debug, Clone, Copy, Default)]
struct Node {
prev: usize,
next: usize,
pub struct Node {
pub prev: usize,
pub next: usize,
}

/// A simple absolute linked list implementation for testing
struct TestAbsoluteList {
nodes: Vec<Node>,
first: usize,
last: usize,
size: usize,
pub struct TestAbsoluteList {
pub nodes: Vec<Node>,
pub first: usize,
pub last: usize,
pub size: usize,
}

impl TestAbsoluteList {
fn new(capacity: usize) -> Self {
pub fn new(capacity: usize) -> Self {
let mut nodes = Vec::with_capacity(capacity + 1);
// Index 0 is reserved as "null"
nodes.resize(capacity + 1, Node::default());
Expand Down Expand Up @@ -88,14 +90,14 @@ impl AbsoluteLinkedList<usize> for TestAbsoluteList {
impl AbsoluteCircularLinkedList<usize> for TestAbsoluteList {}

/// A relative linked list implementation for testing (list head stored in element)
struct TestRelativeList {
nodes: Vec<Node>,
pub struct TestRelativeList {
pub nodes: Vec<Node>,
// Store first/last/size for each "head" element
heads: Vec<(usize, usize, usize)>, // (first, last, size)
pub heads: Vec<(usize, usize, usize)>, // (first, last, size)
}

impl TestRelativeList {
fn new(capacity: usize) -> Self {
pub fn new(capacity: usize) -> Self {
let mut nodes = Vec::with_capacity(capacity + 1);
nodes.resize(capacity + 1, Node::default());
let mut heads = Vec::with_capacity(capacity + 1);
Expand Down Expand Up @@ -152,19 +154,19 @@ impl RelativeCircularLinkedList<usize> for TestRelativeList {}

/// A tree node structure for testing `SizeBalancedTree`
#[derive(Debug, Clone, Copy, Default)]
struct TreeNode {
left: usize,
right: usize,
size: usize,
pub struct TreeNode {
pub left: usize,
pub right: usize,
pub size: usize,
}

/// A simple `SizeBalancedTree` implementation for testing
struct TestTree {
nodes: Vec<TreeNode>,
pub struct TestTree {
pub nodes: Vec<TreeNode>,
}

impl TestTree {
fn new(capacity: usize) -> Self {
pub fn new(capacity: usize) -> Self {
let mut nodes = Vec::with_capacity(capacity + 1);
nodes.resize(capacity + 1, TreeNode::default());
Self { nodes }
Expand Down
Loading