Skip to content

Commit

Permalink
Update: Added headers for doc test
Browse files Browse the repository at this point in the history
  • Loading branch information
yasinldev committed Aug 19, 2023
1 parent 067c2b5 commit ee13389
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
10 changes: 9 additions & 1 deletion src/data_structure/heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ impl<T: PartialOrd> Heap<T>
/// # Examples
///
/// ```
/// use RustyDSA::data_structure::heap::Heap;
/// let heap: Heap<i32> = Heap::new();
/// ```
pub fn new() -> Self
Expand All @@ -32,6 +33,7 @@ impl<T: PartialOrd> Heap<T>
/// # Examples
///
/// ```
/// use RustyDSA::data_structure::heap::Heap;
/// let mut heap: Heap<i32> = Heap::new();
/// heap.push(4);
/// heap.push(5);
Expand All @@ -42,6 +44,11 @@ impl<T: PartialOrd> Heap<T>
self.data.push(element);
}

pub fn peek(&self) -> Option<&T>
{
self.data.get(0)
}

pub fn heapify(&mut self, n: usize, i: usize)
{
let mut largest = i;
Expand Down Expand Up @@ -71,6 +78,7 @@ impl<T: PartialOrd> Heap<T>
/// # Examples
///
/// ```
/// use RustyDSA::data_structure::heap::Heap;
/// let mut heap: Heap<i32> = Heap::new();
/// heap.push(4);
/// heap.push(5);
Expand Down Expand Up @@ -98,7 +106,7 @@ impl<T: PartialOrd> Heap<T>
#[cfg(test)]
mod test
{
use super::*;
use super::Heap;
fn test_heap()
{
let mut heap: Heap<i32> = Heap::new();
Expand Down
6 changes: 2 additions & 4 deletions src/data_structure/linked_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub struct List<T>
len: usize,
}

impl<T> LinkedList<T>
impl<T> List<T>
{
fn new() -> Self
{
Expand Down Expand Up @@ -59,9 +59,7 @@ impl<T> LinkedList<T>
#[cfg(test)]
mod test
{
mod queue;
mod stack;
mod heap;
use super::List as LinkedList;
#[test]
fn test_linked_list()
{
Expand Down
7 changes: 6 additions & 1 deletion src/data_structure/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ impl<T> Queue<T>
/// # Examples
///
/// ```
/// use RustyDSA::data_structure::queue::Queue;
/// let queue: Queue<i32> = Queue::new();
/// ```
pub fn new() -> Self
Expand All @@ -34,6 +35,7 @@ impl<T> Queue<T>
/// # Examples
///
/// ```
/// use RustyDSA::data_structure::queue::Queue;
/// let mut queue: Queue<i32> = Queue::new();
/// queue.enqueue(1);
/// assert_eq!(queue.peek(), Some(&1));
Expand All @@ -49,6 +51,7 @@ impl<T> Queue<T>
/// # Examples
///
/// ```
/// use RustyDSA::data_structure::queue::Queue;
/// let mut queue: Queue<i32> = Queue::new();
/// queue.enqueue(1);
/// let element = queue.dequeue();
Expand All @@ -64,6 +67,7 @@ impl<T> Queue<T>
/// # Examples
///
/// ```
/// use RustyDSA::data_structure::queue::Queue;
/// let mut queue: Queue<i32> = Queue::new();
/// queue.enqueue(1);
/// assert!(!queue.is_null());
Expand All @@ -79,6 +83,7 @@ impl<T> Queue<T>
/// # Examples
///
/// ```
/// use RustyDSA::data_structure::queue::Queue;
/// let mut queue: Queue<i32> = Queue::new();
/// queue.enqueue(1);
/// assert_eq!(queue.peek(), Some(&1));
Expand All @@ -92,7 +97,7 @@ impl<T> Queue<T>
#[cfg(test)]
mod test
{
use super::*;
use super::Queue;
fn test_queue()
{
let mut queue: Queue<i32> = Queue::new();
Expand Down
9 changes: 7 additions & 2 deletions src/data_structure/stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ impl<T> Stack<T>
/// # Examples
///
/// ```
/// use RustyDSA::data_structure::stack::Stack;
/// let stack: Stack<i32> = Stack::new();
/// ```
pub fn new() -> Self
Expand All @@ -32,9 +33,10 @@ impl<T> Stack<T>
/// # Examples
///
/// ```
/// use RustyDSA::data_structure::stack::Stack;
/// let mut stack: Stack<i32> = Stack::new();
/// stack.push(1);
/// assert!(!is_null());
/// assert!(!stack.is_null());
/// ```
pub fn push(&mut self, element: T)
{
Expand All @@ -47,6 +49,7 @@ impl<T> Stack<T>
/// # Examples
///
/// ```
/// use RustyDSA::data_structure::stack::Stack;
/// let mut stack: Stack<i32> = Stack::new();
/// stack.push(1);
/// let element = stack.pop();
Expand All @@ -62,6 +65,7 @@ impl<T> Stack<T>
/// # Examples
///
/// ```
/// use RustyDSA::data_structure::stack::Stack;
/// let mut stack: Stack<i32> = Stack::new();
/// stack.push(1);
/// assert!(!stack.is_null());
Expand All @@ -77,6 +81,7 @@ impl<T> Stack<T>
/// # Examples
///
/// ```
/// use RustyDSA::data_structure::stack::Stack;
/// let mut stack: Stack<i32> = Stack::new();
/// stack.push(1);
/// assert_eq!(stack.peek(), Some(&1));
Expand All @@ -90,7 +95,7 @@ impl<T> Stack<T>
#[cfg(test)]
mod test
{
use super::*;
use super::Stack;
#[test]
fn test_stack()
{
Expand Down

0 comments on commit ee13389

Please sign in to comment.