Skip to content

Commit

Permalink
Added eat.h
Browse files Browse the repository at this point in the history
  • Loading branch information
AnzoDK committed Aug 11, 2021
1 parent 3ef2613 commit 8e969dd
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 1 deletion.
21 changes: 20 additions & 1 deletion .kdev4/RPCommonLib.kdev4
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
BuildItems=@Variant(\x00\x00\x00\t\x00\x00\x00\x00\x01\x00\x00\x00\x0b\x00\x00\x00\x00\x01\x00\x00\x00\x16\x00R\x00P\x00C\x00o\x00m\x00m\x00o\x00n\x00L\x00i\x00b)

[Launch]
Launch Configurations=Launch Configuration 0
Launch Configurations=Launch Configuration 0,Launch Configuration 1

[Launch][Launch Configuration 0]
Configured Launch Modes=execute
Expand All @@ -23,5 +23,24 @@ Use External Terminal=false
Working Directory=
isExecutable=true

[Launch][Launch Configuration 1]
Configured Launch Modes=execute
Configured Launchers=nativeAppLauncher
Name=Laptop Debug
Type=Native Application

[Launch][Launch Configuration 1][Data]
Arguments=
Dependencies=@Variant(\x00\x00\x00\t\x00\x00\x00\x00\x00)
Dependency Action=Nothing
EnvironmentGroup=
Executable=file:///home/anzo/projects/RPCommonLib/test.out
External Terminal=konsole --noclose --workdir %workdir -e %exe
Kill Before Executing Again=4194304
Project Target=
Use External Terminal=false
Working Directory=
isExecutable=true

[Project]
VersionControlSupport=kdevgit
1 change: 1 addition & 0 deletions RPCommon/RPCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
#include "arrayprint.h"
//This header is not useful at the current state and has been disabled
//#include "rpcommonerr.h"
#include "eat.h"
28 changes: 28 additions & 0 deletions RPCommon/eat.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#pragma once
#include <iostream>
#include "strlen.h"
#include "strreverse.h"
void Eat(const char* cs)
{
std::string s = std::string(cs);
size_t len = Cstrlen(cs);
if(len > 0)
{
s = ReverseString(s);
s.erase(s.begin()+s.size()-1);
s = ReverseString(s);
}
cs = s.c_str();

}

void Eat(std::string &s)
{
if(s.size() > 0)
{
s = ReverseString(s);
s.erase(s.begin()+s.size()-1);
s = ReverseString(s);

}
}
37 changes: 37 additions & 0 deletions test1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,37 @@ bool PerformTestVecPrint()
return true;
}

bool PerformTestEat()
{
std::string test1 = "ABCD";
const char* test2 = "ABCD";
std::cout << "Testing Eating of std::string" << std::endl;

Eat(test1);

if(test1 != "BCD")
{
std::cout << TERMINAL_COLOR_RED << test1 << " is not equal to " << "BCD" << TERMINAL_COLOR_RESET << std::endl;
return false;
}

std::cout << TERMINAL_COLOR_GREEN << "Passed!" << TERMINAL_COLOR_RESET << std::endl;

Eat(test2);

if(Cstrcmp(test2,"BCD"))
{
std::cout << TERMINAL_COLOR_RED << test2 << " is not equal to " << "BCD" << TERMINAL_COLOR_RESET << std::endl;
return false;
}

std::cout << TERMINAL_COLOR_GREEN << "Passed!" << TERMINAL_COLOR_RESET << std::endl;

return true;


}


int main()
{
Expand Down Expand Up @@ -224,6 +255,12 @@ int main()
std::cout << TERMINAL_COLOR_RED << "arrayprint failed!" << TERMINAL_COLOR_RESET << std::endl;
exit(0b00010000);
}
std::cout << TERMINAL_COLOR_YELLOW << "Running tests on eat" << TERMINAL_COLOR_RESET << std::endl;
if(!PerformTestEat())
{
std::cout << TERMINAL_COLOR_RED << "eat failed!" << TERMINAL_COLOR_RESET << std::endl;
exit(0b00100000);
}

std::cout << TERMINAL_COLOR_GREEN << "Test Complete - No errors!" << TERMINAL_COLOR_RESET << std::endl;
return 0;
Expand Down

0 comments on commit 8e969dd

Please sign in to comment.