fprime/Fw/DataStructures/test/ut/STest/RedBlackTreeSetOrMapImplTestRules.hpp
Rob Bocchino e9d7f3ab66
Data structure library, phase 2 (#4062)
* Revise RedBlackTree impl docs

* Revise RedBlackTree impl docs

* Revise RedBlackTree impl docs

* Revise RedBlackTree impl docs

* Revise RedBlackTree impl

* Revise RedBlackTree impl

* Revise RedBlackTree impl

* Revise RedBlackTree impl

* Revise RedBlackTree impl

* Revise RedBlackTree impl

* Revise RedBlackTree impl

* Revise RedBlackTree impl

* Revise RedBlackTree impl

* Revise RedBlackTree impl

* Revise RedBlackTree impl

* Revise RedBlackTree impl

* Revise RedBlackTree impl

* Revise RedBlackTree impl

* Revise RedBlackTree impl

* Revise RedBlackTree impl

* Revise RedBlackTree impl

* Revise RedBlackTree impl docs

* Revise RedBlackTree impl

* Revise RedBlackTree impl

* Fix typo

* Revise RedBlackTree impl

* Revise RedBlackTree impl

* Revise RedBlackTree impl

* Revise RedBlackTree impl

* Revise RedBlackTree impl

* Revise RedBlackTree impl

* Revise RedBlackTree impl

* Revise RedBlackTree impl

* Revise RedBlackTree impl docs

* Revise RedBlackTree impl docs

* Revise RedBlackTree impl

* Revise RedBlackTreeImpl docs

* Revise Fw/DataStructures

Reformat code

* Revise Fw/DataStructures

Fix compile errors on Linux

* Revise Fw/DataStructures

Fix compile errors on Linux

* Revise Fw/DataStructures

Fix compile errors on Linux

* Revise Fw/DataStructures

Fix compile errors on Linux

* Fix comments

* Revise Fw/DataStructures

Fix compile errors on Linux

* Revise ArrayMap docs

* Remove helper scripts

* Revise tests for Fw/DataStructures

* Fix spelling

* Fix Markdown link

* Fix uninitialized variable in test

* Fix uninitialized variable in test

* Fix "spelling"

Why is the spelling check enforcing arbitrary rules of style?

* Fix comments

* Revise RedBlackTree impl docs

* Start adding RedBlackTree impl

* Revise tests for ArraySetOrMapImpl

* Revise RedBlackTree impl

* Revise comment

* Revise comment

* Revise RedBlackTree impl

* Revise RedBlackTree impl

* Revise RedBlackTree impl

* Revise RedBlackTree impl

* Revise RedBlackTree impl

* Revise RedBlackTree impl

* Revise ArraySetOrMap impl

* Revise RedBlackTree impl

* Revise RedBlackTree impl

* Revise RedBlackTree impl

* Revise RedBlackTree impl

* Revise RedBlackTree impl

* Revise RedBlackTree impl

* Add RedBlackTree impl tester

* Revise RedBlackTree impl

* Revise RedBlackTree impl

* Revise RedBlackTree impl

* Revise RedBlackTree impl

* Revise RedBlackTree impl

* Fix comments

* Revise RedBlackTree impl

* Fix comments

* Revise comments

* Revise comments

* Revise comments

* Revise statement order for clarity

* Revise unit tests for RedBlackTree impl

* Revise RedBlackTree impl tests

* Revise RedBlackTree impl

* Revise RedBlackTree impl

* Revise RedBlackTree impl

* Add build and clean scripts

Working around regressions in the F Prime build system

* Revise build

Fix warnings

* Revise RedBlackTree impl and tests

* Revise tests for RedBlackTree impl

* Revise RedBlackTree impl and tests

* Revise RedBlackTree tests

Remove debug print statements

* Revise RedBlackTree impl tester

* Revise RedBlackTree impl

* Revise RedBlackTree impl

* Revise RedBlackTree impl

* Revise RedBlackTree impl

* Revise build script

* Revise RedBlackTree tests

* Revise RedBlackTree tests

* Revise RedBlackTree tests

* Revise RedBlackTree tests

* Revise RedBlackTree tests

* Revise RedBlackTree impl tests

* Revise RedBlackTree impl tests

* Revise RedBlackTree impl

* Revise RedBlackTree impl

* Revise RedBlackTree impl tests

* Revise RedBlackTree impl tests

* Revise RedBlackTree impl tests

* Revise RedBlackTree impl tests

* Revise RedBlackTree impl tests

* Revise RedBlackTree impl tests

* Revise RedBlackTree impl test

* Revise RedBlackTree impl

* Revise RedBlackTree impl

* Revise RedBlackTree impl

* Revise RedBlackTree impl

* Revise comment

* Revise RedBlackTree impl and tests

* Revise RedBlackTree impl

* Revise RedBlackTree impl

* Revise RedBlackTree impl

* Revise RedBlackTree impl tests

* Revise RedBlackTree impl tests

* Revise RedBlackTree impl

* Revise RedBlackTree impl tests

* Revise formatting

* Format code

* Revise docs

* Revise docs for Fw/DataStructures

* Revise Array and ExternalArray

Add static assertions

* Revise FifoQueue and Stack

Add static assertions

* Revise ArraySet and ArrayMap

Add static assertions

* Revise docs for ExternalRedBlackTreeMap

* Revise docs for ExternalRedBlackTreeSet

* Revise docs for RedBlackTreeMap

* Revise docs for RedBlackTreeSet

* Revise ExternalRedBlackTreeMap tests

* Refactor ExternalStackTester

* Revise ArrayMap tests

* Add RedBlackTreeMap

* Revise RedBlackTreeMap tests

* Revise RedBlackTreeMap

* Add ExternalRedBlackTreeSet

* Add missing file

* Revise SetConstIterator

* Revise ExternalRedBlackTreeSet tests

* Revise ExternalRedBlackTreeSet tests

* Revise ExternalRedBlackTreeSet tests

* Revise ExternalRedBlackTreeSet tests

* Revise ExternalRedBlackTreeSet tests

* Revise ExternalRedBlackTree tests

* Revise ExternalArraySet tests

* Revise ExternalArraySet tests

* Add RedBlackTreeSet

* Revise RedBlackTreeSet tests

* Refactor ArraySetTest

* Revise RedBlackTreeSetOrMapImpl docs

* Revise array initialization

* Revise comments

* Revise Array initialization

* Revise Array design and implementation

* Revert changes to Fw/DataStructures

* Revise Array

* Revise Array

* Revise Array

* Fix formatting

* Add SizedContainer base class

* Revise StackBase

Make it inherit from SizedContainer
Revise stack tests

* Revise MapBase

Make it inherit from SizedContainer
Revise tests

* Revise SetBase

Make it inherit from SizedContainer
Revise tests

* Revise DataStructures design

Add SizedContainer

* Revise SDD for DataStructures

* Revise DataStructures design

* Revise DataStructures design

* Revise DataStructures design

* Revise DataStructures design

* Fix spelling

* Revise zero-arg constructor for Array

* Revise Array interface

Make it consistent with the arrays generated by FPP

* Fix to assertion

* Format code

* Fix spelling

* Fix spelling

* Add -Wno-comment to suppress warnings for now

* Revise comments

* Revise diagrams

* Fix comment warnings on gcc

* Eliminate tabs

* Remove utility scripts

* Revise placement of break statements

* Rename function

getParentDirection --> getDirectionFromParent

* Add comment

* Add svg diagram

* Add svg diagram

* Add svg files

* Revise diagram

* Replace png with svg

* Replace png with svg

* Replace png with svg

* Revise comment

* Revise SDD for red-black tree

* Revise SDD for red-black tree
2025-10-06 13:26:23 -07:00

200 lines
6.8 KiB
C++

// ======================================================================
// \title RedBlackTreeSetOrMapImplTestRules.hpp
// \author bocchino
// \brief hpp file for RedBlackTreeSetOrMapImpl test rules
// ======================================================================
#ifndef RedBlackTreeSetOrMapImplTestRules_HPP
#define RedBlackTreeSetOrMapImplTestRules_HPP
#include <gtest/gtest.h>
#include "Fw/DataStructures/test/ut/STest/RedBlackTreeSetOrMapImplTestState.hpp"
#include "STest/STest/Pick/Pick.hpp"
#include "STest/STest/Rule/Rule.hpp"
namespace Fw {
namespace RedBlackTreeSetOrMapImplTest {
using Rule = STest::Rule<State>;
namespace Rules {
struct Clear : public Rule {
Clear() : Rule("Clear") {}
bool precondition(const State& state) { return state.impl.getSize() > 0; }
void action(State& state) {
state.impl.clear();
ASSERT_EQ(state.impl.getSize(), 0U);
state.modelMap.clear();
}
};
struct Find : public Rule {
Find() : Rule("Find") {}
bool precondition(const State& state) { return true; }
void action(State& state) {
const auto key = state.getKey();
State::ValueType value = 0;
const auto status = state.impl.find(key, value);
if (state.modelMapContains(key)) {
ASSERT_EQ(status, Success::SUCCESS);
ASSERT_EQ(value, state.modelMap[key]);
} else {
ASSERT_EQ(status, Success::FAILURE);
}
}
};
struct FindExisting : public Rule {
FindExisting() : Rule("FindExisting") {}
bool precondition(const State& state) { return static_cast<FwSizeType>(state.impl.getSize()) > 0; }
void action(State& state) {
const auto size = state.impl.getSize();
const auto index = STest::Pick::startLength(0, static_cast<U32>(size));
auto it = state.impl.begin();
for (FwSizeType i = 0; i < index; i++) {
ASSERT_TRUE(it.isInRange());
it.increment();
}
ASSERT_TRUE(it.isInRange());
const auto key = it.getEntry().getKeyOrElement();
const auto expectedValue = state.modelMap[key];
State::ValueType value = 0;
const auto status = state.impl.find(key, value);
ASSERT_EQ(status, Success::SUCCESS);
ASSERT_EQ(value, expectedValue);
}
};
struct InsertExisting : public Rule {
InsertExisting() : Rule("InsertExisting") {}
bool precondition(const State& state) { return static_cast<FwSizeType>(state.impl.getSize()) > 0; }
void action(State& state) {
state.tester.checkProperties();
const auto size = state.impl.getSize();
const auto index = STest::Pick::startLength(0, static_cast<U32>(size));
auto it = state.impl.begin();
for (FwSizeType i = 0; i < index; i++) {
ASSERT_TRUE(it.isInRange());
it.increment();
}
ASSERT_TRUE(it.isInRange());
const auto key = it.getEntry().getKeyOrElement();
const auto value = state.getValue();
const auto status = state.impl.insert(key, value);
ASSERT_EQ(status, Success::SUCCESS);
state.modelMap[key] = value;
ASSERT_EQ(state.impl.getSize(), size);
state.tester.checkProperties();
}
};
struct InsertFull : public Rule {
InsertFull() : Rule("InsertFull") {}
bool precondition(const State& state) { return static_cast<FwSizeType>(state.impl.getSize()) >= State::capacity; }
void action(State& state) {
state.tester.checkProperties();
const auto key = state.getKey();
const auto value = state.getValue();
const auto size = state.impl.getSize();
const auto expectedStatus = state.modelMapContains(key) ? Success::SUCCESS : Success::FAILURE;
const auto status = state.impl.insert(key, value);
ASSERT_EQ(status, expectedStatus);
ASSERT_EQ(state.impl.getSize(), size);
state.tester.checkProperties();
}
};
struct InsertNotFull : public Rule {
InsertNotFull() : Rule("InsertNotFull") {}
bool precondition(const State& state) { return static_cast<FwSizeType>(state.impl.getSize()) < State::capacity; }
void action(State& state) {
state.tester.checkProperties();
const auto key = state.getKey();
const auto value = state.getValue();
const auto size = state.impl.getSize();
const auto expectedSize = state.modelMapContains(key) ? size : size + 1;
const auto status = state.impl.insert(key, value);
ASSERT_EQ(status, Success::SUCCESS);
ASSERT_EQ(state.impl.getSize(), expectedSize);
state.modelMap[key] = value;
state.tester.checkProperties();
}
};
struct Remove : public Rule {
Remove() : Rule("Remove") {}
bool precondition(const State& state) { return true; }
void action(State& state) {
state.tester.checkProperties();
const auto size = state.impl.getSize();
ASSERT_EQ(size, state.modelMap.size());
const auto key = state.getKey();
State::ValueType value = 0;
const auto status = state.impl.remove(key, value);
if (state.modelMap.count(key) != 0) {
ASSERT_EQ(status, Success::SUCCESS);
ASSERT_EQ(value, state.modelMap[key]);
ASSERT_EQ(state.impl.getSize(), size - 1);
} else {
ASSERT_EQ(status, Success::FAILURE);
ASSERT_EQ(state.impl.getSize(), size);
}
(void)state.modelMap.erase(key);
ASSERT_EQ(state.impl.getSize(), state.modelMap.size());
state.tester.checkProperties();
}
};
struct RemoveExisting : public Rule {
RemoveExisting() : Rule("RemoveExisting") {}
bool precondition(const State& state) { return static_cast<FwSizeType>(state.impl.getSize()) > 0; }
void action(State& state) {
state.tester.checkProperties();
const auto size = state.impl.getSize();
const auto index = STest::Pick::startLength(0, static_cast<U32>(size));
auto it = state.impl.begin();
for (FwSizeType i = 0; i < index; i++) {
ASSERT_TRUE(it.isInRange());
it.increment();
}
ASSERT_TRUE(it.isInRange());
const auto key = it.getEntry().getKeyOrElement();
const auto expectedValue = state.modelMap[key];
State::ValueType value = 0;
const auto status = state.impl.remove(key, value);
ASSERT_EQ(status, Success::SUCCESS);
ASSERT_EQ(value, expectedValue);
const auto n = state.modelMap.erase(key);
ASSERT_EQ(n, 1U);
ASSERT_EQ(state.impl.getSize(), state.modelMap.size());
state.tester.checkProperties();
}
};
extern Clear clear;
extern Find find;
extern FindExisting findExisting;
extern InsertExisting insertExisting;
extern InsertFull insertFull;
extern InsertNotFull insertNotFull;
extern Remove remove;
extern RemoveExisting removeExisting;
} // namespace Rules
} // namespace RedBlackTreeSetOrMapImplTest
} // namespace Fw
#endif