Skip to content

Commit f7d8976

Browse files
committed
created macro for STACK_TYPE format in printf; changed tests to double; other small changes
1 parent 306a7df commit f7d8976

File tree

6 files changed

+13
-16
lines changed

6 files changed

+13
-16
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
cmake_minimum_required(VERSION 3.14)
2-
project(Onegin)
2+
project(Stack)
33

44
set(CMAKE_CXX_COMPILER "/usr/bin/clang++" CACHE string "clang compiler" FORCE) #TODO check if clang is present when COVERAGE needed
55

gstack-config.h

Lines changed: 0 additions & 7 deletions
This file was deleted.

gstack-header.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@
4949
#include <sys/mman.h>
5050
#endif
5151

52-
#include "gstack-config.h"
53-
5452

5553
//===========================================
5654
// Stack options configuration

gstack.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ static stack_status stack_dumpToStream(const stack *this_, FILE *out)
458458
size_t cap = fmin(this_->len, capacity); // in case structure is corrupt and len > capacity
459459

460460
for (size_t i = 0; i < cap; ++i) {
461-
fprintf(out, "| * %d\n", this_->data[i]); //TODO add generalized print // `*` for in-use cells
461+
fprintf(out, "| * " ELEM_PRINTF_FORM "\n", this_->data[i]); //TODO add generalized print // `*` for in-use cells
462462
}
463463

464464
bool printAll = true;

stack-demo.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
typedef int STACK_TYPE;
2+
#define ELEM_PRINTF_FORM "%d"
3+
14
#include "gstack.h"
25
#include "gtest/gtest.h"
36

stack-test.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#include "gtest/gtest.h"
22

3+
typedef double STACK_TYPE;
4+
#define ELEM_PRINTF_FORM "%g"
5+
36
#include "gstack.h"
47

58
#include <random>
@@ -63,7 +66,7 @@ TEST(PushPop, Manual)
6366
stack_push(&S, 14);
6467
stack_dump(&S);
6568

66-
int res = 0;
69+
STACK_TYPE res = 0;
6770
stack_pop(&S, &res);
6871
EXPECT_EQ(res, 14);
6972

@@ -75,7 +78,7 @@ TEST(PushPop, Manual)
7578
TEST(PushPop, Random)
7679
{
7780
stack S = {};
78-
std::stack<int> STD = {};
81+
std::stack<STACK_TYPE> STD = {};
7982

8083
stack_ctor(&S);
8184

@@ -84,12 +87,12 @@ TEST(PushPop, Random)
8487
for (size_t i = 0; i < iterations; ++i) {
8588
EXPECT_EQ(S.len, STD.size());
8689
if (rnd() % 10 < 7) {
87-
int item = rnd();
90+
STACK_TYPE item = rnd();
8891
stack_push(&S, item);
8992
STD.push(item);
9093
}
9194
else if (!(S.len || STD.size())) {
92-
int item = 0;
95+
STACK_TYPE item = 0;
9396
stack_pop(&S, &item);
9497
EXPECT_EQ(item, STD.top());
9598
STD.pop();
@@ -98,7 +101,7 @@ TEST(PushPop, Random)
98101
EXPECT_EQ(S.len, STD.size());
99102
while (S.len)
100103
{
101-
int item = 0;
104+
STACK_TYPE item = 0;
102105
stack_pop(&S, &item);
103106
EXPECT_EQ(item, STD.top());
104107
STD.pop();

0 commit comments

Comments
 (0)