Skip to content

Commit

Permalink
add tests, update version
Browse files Browse the repository at this point in the history
  • Loading branch information
nkaaf committed Oct 27, 2023
1 parent d6c6900 commit b5c537c
Show file tree
Hide file tree
Showing 19 changed files with 2,109 additions and 15 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ html
# VSCode
.vscode

# PlatformIO for testing
# PlatformIO
.pio
test
lib
src/main.cpp
include
Expand Down
2 changes: 1 addition & 1 deletion Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ PROJECT_NAME = "Arduino List Library"
# could be handy for archiving the generated documentation or if some version
# control system is used.

PROJECT_NUMBER = 2.1.4
PROJECT_NUMBER = 3.0.0-alpha1

# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a
Expand Down
7 changes: 2 additions & 5 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,13 @@ addAll KEYWORD2
addFirst KEYWORD2
addLast KEYWORD2
clear KEYWORD2
getValue KEYWORD2
getPointer KEYWORD2
get KEYWORD2
getMutableValue KEYWORD2
remove KEYWORD2
removeFirst KEYWORD2
removeLast KEYWORD2
removeAll KEYWORD2
getSize KEYWORD2
isMutable KEYWORD2
isEmpty KEYWORD2
toArray KEYWORD2
fromArray KEYWORD2
sort KEYWORD2
equals KEYWORD2
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "List",
"version": "2.1.4",
"version": "3.0.0",
"description": "The Ultimate Collection of Lists. This library extends the Arduino ecosystem with the functionality of several easy-to-use lists for numerous purposes.",
"keywords": [
"arduino",
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=List
version=2.1.4
version=3.0.0
author=Niklas Kaaf <[email protected]>
maintainer=Niklas Kaaf <[email protected]>
sentence=The Ultimate Collection of Lists
Expand Down
2 changes: 0 additions & 2 deletions src/AbstractList.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@

#include <stdlib.h>

// TODO: update keywords

/*!
* @brief Abstract class from which all lists can be derived.
*
Expand Down
2 changes: 1 addition & 1 deletion src/DoubleLinkedList.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* easy-to-use list implementations. They are specially designed and optimized
* for different purposes.
*
* Copyright (C) 2022 Niklas Kaaf
* Copyright (C) 2022-2023 Niklas Kaaf
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down
2 changes: 1 addition & 1 deletion src/List.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*
* This file is part of the List library.
*
* Copyright (C) 2021-2022 Niklas Kaaf
* Copyright (C) 2021-2023 Niklas Kaaf
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down
2 changes: 1 addition & 1 deletion src/SingleLinkedList.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* easy-to-use list implementations. They are specially designed and optimized
* for different purposes.
*
* Copyright (C) 2021-2022 Niklas Kaaf
* Copyright (C) 2021-2023 Niklas Kaaf
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down
258 changes: 258 additions & 0 deletions test/test_immutable_+/test_immutable_+.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,258 @@
#include <Arduino.h>

#include "unity.h"

#include <List.hpp>

// ---------- In different scope (ds) ---------- //

void add_ds_rvalue_primitive(void)
{
List<int> list;

{
list + 1;
}
TEST_ASSERT_EQUAL_INT(1, list[0]);
TEST_ASSERT_EQUAL_INT(1, list.getSize());

{
list + 2;
}
TEST_ASSERT_EQUAL_INT(1, list[0]);
TEST_ASSERT_EQUAL_INT(2, list[1]);
TEST_ASSERT_EQUAL_INT(2, list.getSize());
}

void add_ds_lvalue_primitive(void)
{
List<int> list;

{
int a = 1;
list + a;

TEST_ASSERT_EQUAL_INT(1, a);
a = 2;
}
TEST_ASSERT_EQUAL_INT(1, list[0]);
TEST_ASSERT_EQUAL_INT(1, list.getSize());

{
int b = 2;
list + b;

TEST_ASSERT_EQUAL_INT(2, b);
b = 3;
}
TEST_ASSERT_EQUAL_INT(1, list[0]);
TEST_ASSERT_EQUAL_INT(2, list[1]);
TEST_ASSERT_EQUAL_INT(2, list.getSize());
}

void add_ds_rvalue_class(void)
{
List<String> list;

{
list + "1";
}
TEST_ASSERT_EQUAL_STRING("1", list[0].c_str());
TEST_ASSERT_EQUAL_INT(1, list.getSize());

{
list + "2";
}
TEST_ASSERT_EQUAL_STRING("1", list[0].c_str());
TEST_ASSERT_EQUAL_STRING("2", list[1].c_str());
TEST_ASSERT_EQUAL_INT(2, list.getSize());
}

void add_ds_lvalue_class(void)
{
List<String> list;

{
String a = "1";
list + a;

TEST_ASSERT_EQUAL_STRING("1", a.c_str());
a = "2";
}
TEST_ASSERT_EQUAL_STRING("1", list[0].c_str());
TEST_ASSERT_EQUAL_INT(1, list.getSize());

{
String b = "2";
list + b;

TEST_ASSERT_EQUAL_STRING("2", b.c_str());
b = "3";
}
TEST_ASSERT_EQUAL_STRING("1", list[0].c_str());
TEST_ASSERT_EQUAL_STRING("2", list[1].c_str());
TEST_ASSERT_EQUAL_INT(2, list.getSize());
}

// ---------- In same scope (ss) ---------- //

void add_ss_rvalue_primitive(void)
{
List<int> list;

list + 1;
TEST_ASSERT_EQUAL_INT(1, list[0]);
TEST_ASSERT_EQUAL_INT(1, list.getSize());

list + 2;
TEST_ASSERT_EQUAL_INT(1, list[0]);
TEST_ASSERT_EQUAL_INT(2, list[1]);
TEST_ASSERT_EQUAL_INT(2, list.getSize());
}

void add_ss_lvalue_primitive(void)
{
List<int> list;

int a = 1, b = 2;

list + a;

TEST_ASSERT_EQUAL_INT(1, a);
a = 2;
TEST_ASSERT_EQUAL_INT(1, list[0]);
TEST_ASSERT_EQUAL_INT(1, list.getSize());

list + b;

TEST_ASSERT_EQUAL_INT(2, b);
b = 3;
TEST_ASSERT_EQUAL_INT(1, list[0]);
TEST_ASSERT_EQUAL_INT(2, list[1]);
TEST_ASSERT_EQUAL_INT(2, list.getSize());
}

void add_ss_rvalue_class(void)
{
List<String> list;

list + "1";
TEST_ASSERT_EQUAL_STRING("1", list[0].c_str());
TEST_ASSERT_EQUAL_INT(1, list.getSize());

list + "2";
TEST_ASSERT_EQUAL_STRING("1", list[0].c_str());
TEST_ASSERT_EQUAL_STRING("2", list[1].c_str());
TEST_ASSERT_EQUAL_INT(2, list.getSize());
}

void add_ss_lvalue_class(void)
{
List<String> list;

String a = "1", b = "2";

list + a;

TEST_ASSERT_EQUAL_STRING("1", a.c_str());
a = "2";
TEST_ASSERT_EQUAL_STRING("1", list[0].c_str());
TEST_ASSERT_EQUAL_INT(1, list.getSize());

list + b;

TEST_ASSERT_EQUAL_STRING("2", b.c_str());
b = "3";
TEST_ASSERT_EQUAL_STRING("1", list[0].c_str());
TEST_ASSERT_EQUAL_STRING("2", list[1].c_str());
TEST_ASSERT_EQUAL_INT(2, list.getSize());
}

// ---------- void operator+(AbstractList<T> &list) ---------- //

void addAll_primitive(void)
{
List<int> fromList;
List<int> toList;

toList.add(1);
toList.add(2);
toList.add(3);
fromList.add(4);
fromList.add(5);
fromList.add(6);

toList + fromList;

TEST_ASSERT_EQUAL_INT(4, fromList[0]);
TEST_ASSERT_EQUAL_INT(5, fromList[1]);
TEST_ASSERT_EQUAL_INT(6, fromList[2]);
TEST_ASSERT_EQUAL_INT(3, fromList.getSize());

fromList.clear();

TEST_ASSERT_EQUAL_INT(1, toList[0]);
TEST_ASSERT_EQUAL_INT(2, toList[1]);
TEST_ASSERT_EQUAL_INT(3, toList[2]);
TEST_ASSERT_EQUAL_INT(4, toList[3]);
TEST_ASSERT_EQUAL_INT(5, toList[4]);
TEST_ASSERT_EQUAL_INT(6, toList[5]);
TEST_ASSERT_EQUAL_INT(6, toList.getSize());
}

void addAll_class(void)
{
List<String> fromList;
List<String> toList;

toList.add("1");
toList.add("2");
toList.add("3");
fromList.add("4");
fromList.add("5");
fromList.add("6");

toList + fromList;

TEST_ASSERT_EQUAL_STRING("4", fromList[0].c_str());
TEST_ASSERT_EQUAL_STRING("5", fromList[1].c_str());
TEST_ASSERT_EQUAL_STRING("6", fromList[2].c_str());
TEST_ASSERT_EQUAL_INT(3, fromList.getSize());

fromList.clear();

TEST_ASSERT_EQUAL_STRING("1", toList[0].c_str());
TEST_ASSERT_EQUAL_STRING("2", toList[1].c_str());
TEST_ASSERT_EQUAL_STRING("3", toList[2].c_str());
TEST_ASSERT_EQUAL_STRING("4", toList[3].c_str());
TEST_ASSERT_EQUAL_STRING("5", toList[4].c_str());
TEST_ASSERT_EQUAL_STRING("6", toList[5].c_str());
TEST_ASSERT_EQUAL_INT(6, toList.getSize());
}

void setup()
{
UNITY_BEGIN();

// different scope tests
RUN_TEST(add_ds_rvalue_primitive);
RUN_TEST(add_ds_lvalue_primitive);
RUN_TEST(add_ds_rvalue_class);
RUN_TEST(add_ds_lvalue_class);

// same scope tests
RUN_TEST(add_ss_rvalue_primitive);
RUN_TEST(add_ss_lvalue_primitive);
RUN_TEST(add_ss_rvalue_class);
RUN_TEST(add_ss_lvalue_class);

// ---------- void operator+(AbstractList<T> &list) ---------- //
RUN_TEST(addAll_primitive);
RUN_TEST(addAll_class);

UNITY_END();
}

void loop()
{
}
Loading

0 comments on commit b5c537c

Please sign in to comment.