Brett 2024-09-02 12:38:50 -04:00
parent ab482f1a1c
commit a7645d9dde
3 changed files with 33 additions and 10 deletions

View File

@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.20) cmake_minimum_required(VERSION 3.20)
include(cmake/color.cmake) include(cmake/color.cmake)
set(BLT_VERSION 0.19.4) set(BLT_VERSION 0.19.5)
set(BLT_TEST_VERSION 0.0.1) set(BLT_TEST_VERSION 0.0.1)
set(BLT_TARGET BLT) set(BLT_TARGET BLT)

View File

@ -7,43 +7,61 @@
#ifndef BLT_TESTS_AVERAGES_H #ifndef BLT_TESTS_AVERAGES_H
#define BLT_TESTS_AVERAGES_H #define BLT_TESTS_AVERAGES_H
namespace blt { namespace blt
{
template<typename T, int Size> template<typename T, int Size>
class averagizer_o_matic { class averagizer_o_matic
{
private: private:
T* data; T* data;
int index = 0; int index = 0;
int m_default = 0; int m_default = 0;
public: public:
averagizer_o_matic(): averagizer_o_matic(0) {} averagizer_o_matic(): averagizer_o_matic(0)
explicit averagizer_o_matic(T default_value){ {}
explicit averagizer_o_matic(T default_value)
{
data = new T[Size]; data = new T[Size];
for (int i = 0; i < Size; i++){ for (int i = 0; i < Size; i++)
{
data[i] = default_value; data[i] = default_value;
} }
m_default = default_value; m_default = default_value;
} }
void insert(T t){ void insert(T t)
{
data[index++] = t; data[index++] = t;
if (index >= Size) if (index >= Size)
index = 0; index = 0;
} }
T average(){ T average()
{
T total = 0; T total = 0;
for (int i = 0; i < Size; i++){ for (int i = 0; i < Size; i++)
{
total += data[i]; total += data[i];
} }
return total / Size; return total / Size;
} }
~averagizer_o_matic(){ ~averagizer_o_matic()
{
delete[] data; delete[] data;
} }
}; };
template<typename A, typename B>
double average(A a, B b)
{
if (b == 0)
return 0;
return static_cast<double>(a) / static_cast<double>(b);
}
} }
#endif //BLT_TESTS_AVERAGES_H #endif //BLT_TESTS_AVERAGES_H

View File

@ -158,6 +158,11 @@ namespace blt::string
return std::to_string(convert.getConvertedRound<decimal_places>()) + convert.type_string(); return std::to_string(convert.getConvertedRound<decimal_places>()) + convert.type_string();
} }
static inline std::string bytes_to_pretty(blt::u64 bytes)
{
return byte_convert_t(bytes).convert_to_nearest_type().to_pretty_string();
}
// TODO: update table formatter to use these! // TODO: update table formatter to use these!
/** /**
* creates a line starting/ending with ending char filled between with spacing char * creates a line starting/ending with ending char filled between with spacing char