mirror of
https://github.com/jorenchik/testing-spring-2024.git
synced 2025-10-21 20:10:36 +00:00
initial commit
Src directory with simple project with tests and one library. README. CLang format config file.
This commit is contained in:
commit
b84cde3614
2
.clang-format
Normal file
2
.clang-format
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
BasedOnStyle: LLVM
|
||||||
|
IndentWidth: 4
|
||||||
74
.gitignore
vendored
Normal file
74
.gitignore
vendored
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
# Prerequisites
|
||||||
|
*.d
|
||||||
|
|
||||||
|
# Object files
|
||||||
|
*.o
|
||||||
|
*.ko
|
||||||
|
*.obj
|
||||||
|
*.elf
|
||||||
|
|
||||||
|
# Linker output
|
||||||
|
*.ilk
|
||||||
|
*.map
|
||||||
|
*.exp
|
||||||
|
|
||||||
|
# Precompiled Headers
|
||||||
|
*.gch
|
||||||
|
*.pch
|
||||||
|
|
||||||
|
# Libraries
|
||||||
|
*.lib
|
||||||
|
*.a
|
||||||
|
*.la
|
||||||
|
*.lo
|
||||||
|
|
||||||
|
# Shared objects (inc. Windows DLLs)
|
||||||
|
*.dll
|
||||||
|
*.so
|
||||||
|
*.so.*
|
||||||
|
*.dylib
|
||||||
|
|
||||||
|
# Executables
|
||||||
|
*.exe
|
||||||
|
*.out
|
||||||
|
*.app
|
||||||
|
*.i*86
|
||||||
|
*.x86_64
|
||||||
|
*.hex
|
||||||
|
|
||||||
|
# Debug files
|
||||||
|
*.dSYM/
|
||||||
|
*.su
|
||||||
|
*.idb
|
||||||
|
*.pdb
|
||||||
|
|
||||||
|
# Kernel Module Compile Results
|
||||||
|
*.mod*
|
||||||
|
*.cmd
|
||||||
|
.tmp_versions/
|
||||||
|
modules.order
|
||||||
|
Module.symvers
|
||||||
|
Mkfile.old
|
||||||
|
dkms.conf
|
||||||
|
|
||||||
|
# CMake
|
||||||
|
CMakeLists.txt.user
|
||||||
|
CMakeCache.txt
|
||||||
|
CMakeFiles
|
||||||
|
CMakeScripts
|
||||||
|
Testing
|
||||||
|
Makefile
|
||||||
|
cmake_install.cmake
|
||||||
|
install_manifest.txt
|
||||||
|
compile_commands.json
|
||||||
|
CTestTestfile.cmake
|
||||||
|
_deps
|
||||||
|
build
|
||||||
|
|
||||||
|
# Clang
|
||||||
|
.cache
|
||||||
|
|
||||||
|
|
||||||
|
input.txt
|
||||||
|
output.txt
|
||||||
|
|
||||||
34
README.md
Normal file
34
README.md
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
# Overview
|
||||||
|
|
||||||
|
## Project
|
||||||
|
|
||||||
|
This is a simple C++ project that includes the function for our collegues to
|
||||||
|
test. The function (i.e., the main function and the subfunctions used in it) is
|
||||||
|
located in ``main_lib.cpp``.
|
||||||
|
|
||||||
|
## Additional libraries and executables
|
||||||
|
|
||||||
|
Our library ``Prep`` is concerned with preparation of data prior to the function
|
||||||
|
call. ``test.cpp`` is a single test file that will contain the tests of our collegues
|
||||||
|
and our own development tests. GTest is used for tests.
|
||||||
|
|
||||||
|
# Usage
|
||||||
|
|
||||||
|
## Compilation
|
||||||
|
|
||||||
|
Compilation on Linux requires cmake and CXX compiler (e.g., g++).
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd src
|
||||||
|
mkdir build
|
||||||
|
cd build
|
||||||
|
cmake ../
|
||||||
|
cmake --build .
|
||||||
|
```
|
||||||
|
|
||||||
|
Resulting binaries are ``build/main`` - the program and ``build/runtests`` to
|
||||||
|
run tests specified in ``test.cpp``.
|
||||||
|
|
||||||
|
# TODOS
|
||||||
|
|
||||||
|
- Translate README in Latvian
|
||||||
36
src/CMakeLists.txt
Normal file
36
src/CMakeLists.txt
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.1...3.28)
|
||||||
|
|
||||||
|
enable_testing()
|
||||||
|
|
||||||
|
project(
|
||||||
|
Template
|
||||||
|
VERSION 0.1.0
|
||||||
|
LANGUAGES CXX)
|
||||||
|
|
||||||
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||||
|
|
||||||
|
add_subdirectory(Cppunit)
|
||||||
|
add_subdirectory(Prep)
|
||||||
|
|
||||||
|
add_executable(main main.cpp)
|
||||||
|
add_library(mainLib main_lib.cpp main_lib.h)
|
||||||
|
target_link_libraries(main PUBLIC mainLib)
|
||||||
|
target_link_libraries(mainLib PUBLIC prepLib)
|
||||||
|
target_include_directories(main PUBLIC "${PROJECT_BINARY_DIR}"
|
||||||
|
"${PROJECT_SOURCE_DIR}/Prep")
|
||||||
|
target_include_directories(mainLib PUBLIC "${PROJECT_BINARY_DIR}"
|
||||||
|
"${PROJECT_SOURCE_DIR}/Prep")
|
||||||
|
|
||||||
|
include(FetchContent)
|
||||||
|
FetchContent_Declare(
|
||||||
|
googletest
|
||||||
|
URL https://github.com/google/googletest/archive/5376968f6948923e2411081fd9372e71a59d8e77.zip
|
||||||
|
)
|
||||||
|
FetchContent_MakeAvailable(googletest)
|
||||||
|
|
||||||
|
add_executable(runtests test.cpp)
|
||||||
|
target_link_libraries(runtests PUBLIC mainLib gtest gtest_main)
|
||||||
|
target_include_directories(runtests PUBLIC "${PROJECT_BINARY_DIR}")
|
||||||
|
|
||||||
|
include(GoogleTest)
|
||||||
|
gtest_discover_tests(runtests)
|
||||||
1
src/Cppunit/CMakeLists.txt
Normal file
1
src/Cppunit/CMakeLists.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
add_library(cppunit cppunit.cpp cppunit.h)
|
||||||
0
src/Cppunit/cppunit.cpp
Normal file
0
src/Cppunit/cppunit.cpp
Normal file
78
src/Cppunit/cppunit.h
Normal file
78
src/Cppunit/cppunit.h
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
|
||||||
|
#ifndef CPPUNIT_H
|
||||||
|
#define CPPUNIT_H
|
||||||
|
|
||||||
|
// Required headers, or just use #include <bits/stdc++.h>
|
||||||
|
#include <cstring>
|
||||||
|
#include <ctime>
|
||||||
|
#include <iostream>
|
||||||
|
#include <sstream>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
// CPlusPlusUnit - C++ Unit testing TDD framework (github.com/cppunit/cppunit)
|
||||||
|
class Cppunit {
|
||||||
|
public:
|
||||||
|
#define CHECK(a, b) \
|
||||||
|
check<long long>(a, b, #a, #b, __FILE__, __LINE__, __FUNCTION__);
|
||||||
|
#define CHECKT(a) \
|
||||||
|
check<bool>(a, true, #a, "true", __FILE__, __LINE__, __FUNCTION__);
|
||||||
|
#define CHECKS(a, b) check<cs>(a, b, #a, #b, __FILE__, __LINE__, __FUNCTION__);
|
||||||
|
typedef const std::string &cs;
|
||||||
|
int checks, fails;
|
||||||
|
std::ostringstream serr;
|
||||||
|
std::istringstream *in;
|
||||||
|
Cppunit() { checks = fails = 0; }
|
||||||
|
void test_cin(cs s) {
|
||||||
|
in = new std::istringstream(s);
|
||||||
|
std::cin.rdbuf(in->rdbuf());
|
||||||
|
}
|
||||||
|
void fail_hdr(cs stra, cs strb, cs file, int line, cs func) {
|
||||||
|
serr << "=================================================="
|
||||||
|
<< std::endl;
|
||||||
|
serr << "FAIL: " << func << std::endl;
|
||||||
|
serr << "--------------------------------------------------"
|
||||||
|
<< std::endl;
|
||||||
|
serr << "File \"" << file << "\", line " << line << " in " << func
|
||||||
|
<< std::endl;
|
||||||
|
serr << " Checking " << stra << " == " << strb << std::endl;
|
||||||
|
}
|
||||||
|
template <typename T>
|
||||||
|
void check(T a, T b, cs stra, cs strb, cs file, int line, cs func) {
|
||||||
|
checks++;
|
||||||
|
if (a == b) {
|
||||||
|
std::cout << ".";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
fails++;
|
||||||
|
std::cout << "F";
|
||||||
|
fail_hdr(stra, strb, file, line, func);
|
||||||
|
serr << " Error: \"" << a << "\" ! = \"" << b << "\"" << std::endl
|
||||||
|
<< std::endl;
|
||||||
|
}
|
||||||
|
virtual void single_test() {}
|
||||||
|
virtual void test_list() { single_test(); }
|
||||||
|
double dclock() { return double(clock()) / CLOCKS_PER_SEC; }
|
||||||
|
int status() {
|
||||||
|
std::cout << std::endl;
|
||||||
|
if (fails)
|
||||||
|
std::cout << serr.str();
|
||||||
|
std::cout << "--------------------------------------------------"
|
||||||
|
<< std::endl;
|
||||||
|
std::cout << "Ran " << checks << " checks in " << dclock() << "s"
|
||||||
|
<< std::endl
|
||||||
|
<< std::endl;
|
||||||
|
if (fails)
|
||||||
|
std::cout << "FAILED (failures=" << fails << ")";
|
||||||
|
else
|
||||||
|
std::cout << "OK" << std::endl;
|
||||||
|
return fails > 0;
|
||||||
|
}
|
||||||
|
int run() {
|
||||||
|
std::streambuf *ocin = std::cin.rdbuf();
|
||||||
|
test_list();
|
||||||
|
std::cin.rdbuf(ocin);
|
||||||
|
return status();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // CPPUNIT_H
|
||||||
1
src/Prep/CMakeLists.txt
Normal file
1
src/Prep/CMakeLists.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
add_library(prepLib Prep.cpp Prep.h)
|
||||||
3
src/Prep/Prep.cpp
Normal file
3
src/Prep/Prep.cpp
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
#include "Prep.h"
|
||||||
|
|
||||||
|
int add(int a, int b) { return a + b; }
|
||||||
6
src/Prep/Prep.h
Normal file
6
src/Prep/Prep.h
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#ifndef PREP_H
|
||||||
|
#define PREP_H
|
||||||
|
|
||||||
|
int add(int a, int b);
|
||||||
|
|
||||||
|
#endif
|
||||||
7
src/main.cpp
Normal file
7
src/main.cpp
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
#include "main_lib.h"
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
int main(int argc, char *argv[]) {
|
||||||
|
run();
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
||||||
7
src/main_lib.cpp
Normal file
7
src/main_lib.cpp
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
#include "main_lib.h"
|
||||||
|
#include "Prep.h"
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
void run() { std::cout << add(2, 2) << std::endl; }
|
||||||
|
|
||||||
|
int functionToTest(int a) { return a * 2; }
|
||||||
2
src/main_lib.h
Normal file
2
src/main_lib.h
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
void run();
|
||||||
|
int functionToTest(int);
|
||||||
31
src/memoryCalculations.md
Normal file
31
src/memoryCalculations.md
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
struct Muitnieks {
|
||||||
|
uint employeeAvailable ID 4b
|
||||||
|
uint timeToServe 4b
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Citizen {
|
||||||
|
uint timeArrived; 4b
|
||||||
|
uint timeFinish; 4b
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
size for Employee:
|
||||||
|
Worker count: 99
|
||||||
|
Citizen count: 4'000'000
|
||||||
|
|
||||||
|
99 * 8b + 4'000'000 * 8b = 792b + 32'000'000b =
|
||||||
|
=
|
||||||
|
|
||||||
|
|
||||||
|
How to determine the amount of time which can lie about
|
||||||
|
the queue?
|
||||||
|
|
||||||
|
Maximum time of serving is 100'000
|
||||||
|
|
||||||
|
Lets say we start serving someone at x:
|
||||||
|
How can we be sure that no one would be faster?
|
||||||
|
|
||||||
|
It must be 100001 lower than current time,
|
||||||
|
so if the time will be less by this time there will and
|
||||||
|
it will we in priority
|
||||||
2
src/publicTests/customs.i1
Normal file
2
src/publicTests/customs.i1
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
1 1 10 10
|
||||||
|
X
|
||||||
4
src/publicTests/customs.i2
Normal file
4
src/publicTests/customs.i2
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
1 1 10 10
|
||||||
|
P 1
|
||||||
|
N 2
|
||||||
|
X
|
||||||
4
src/publicTests/customs.i3
Normal file
4
src/publicTests/customs.i3
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
1 1 10 10
|
||||||
|
P 1
|
||||||
|
P 2
|
||||||
|
X
|
||||||
13
src/publicTests/customs.i4
Normal file
13
src/publicTests/customs.i4
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
2 1 10 10
|
||||||
|
T P 2 21
|
||||||
|
P 1
|
||||||
|
P 2
|
||||||
|
P 3
|
||||||
|
P 4
|
||||||
|
P 5
|
||||||
|
P 6
|
||||||
|
P 7
|
||||||
|
P 8
|
||||||
|
P 9
|
||||||
|
P 10
|
||||||
|
X
|
||||||
13
src/publicTests/customs.i5
Normal file
13
src/publicTests/customs.i5
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
1 5 10 10
|
||||||
|
T N 1 5
|
||||||
|
T N 3 3
|
||||||
|
T N 5 1
|
||||||
|
T N 4 2
|
||||||
|
T N 2 5
|
||||||
|
N 997
|
||||||
|
N 1001
|
||||||
|
N 1002
|
||||||
|
N 1003
|
||||||
|
N 1004
|
||||||
|
N 1005
|
||||||
|
X
|
||||||
14
src/publicTests/customs.i6
Normal file
14
src/publicTests/customs.i6
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
2 3 10 50
|
||||||
|
T P 1 7
|
||||||
|
T N 2 80
|
||||||
|
P 1
|
||||||
|
N 2
|
||||||
|
N 10
|
||||||
|
N 20
|
||||||
|
N 30
|
||||||
|
N 40
|
||||||
|
P 45
|
||||||
|
P 50
|
||||||
|
P 53
|
||||||
|
N 60
|
||||||
|
X
|
||||||
2004
src/publicTests/customs.i7
Normal file
2004
src/publicTests/customs.i7
Normal file
File diff suppressed because it is too large
Load Diff
1
src/publicTests/customs.o1
Normal file
1
src/publicTests/customs.o1
Normal file
@ -0,0 +1 @@
|
|||||||
|
nothing
|
||||||
2
src/publicTests/customs.o2
Normal file
2
src/publicTests/customs.o2
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
1 11
|
||||||
|
2 12
|
||||||
2
src/publicTests/customs.o3
Normal file
2
src/publicTests/customs.o3
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
1 11
|
||||||
|
2 21
|
||||||
10
src/publicTests/customs.o4
Normal file
10
src/publicTests/customs.o4
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
1 11
|
||||||
|
3 21
|
||||||
|
2 23
|
||||||
|
4 31
|
||||||
|
6 41
|
||||||
|
5 44
|
||||||
|
7 51
|
||||||
|
9 61
|
||||||
|
8 65
|
||||||
|
10 71
|
||||||
6
src/publicTests/customs.o5
Normal file
6
src/publicTests/customs.o5
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
997 1002
|
||||||
|
1001 1006
|
||||||
|
1003 1006
|
||||||
|
1004 1006
|
||||||
|
1005 1006
|
||||||
|
1002 1007
|
||||||
10
src/publicTests/customs.o6
Normal file
10
src/publicTests/customs.o6
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
1 8
|
||||||
|
45 52
|
||||||
|
2 52
|
||||||
|
53 60
|
||||||
|
50 60
|
||||||
|
20 70
|
||||||
|
10 90
|
||||||
|
30 102
|
||||||
|
40 120
|
||||||
|
60 170
|
||||||
2000
src/publicTests/customs.o7
Normal file
2000
src/publicTests/customs.o7
Normal file
File diff suppressed because it is too large
Load Diff
9
src/test.cpp
Normal file
9
src/test.cpp
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
#include "Prep.h"
|
||||||
|
#include "main_lib.h"
|
||||||
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
|
// TEST(TestSuiteName, testName) {...}
|
||||||
|
TEST(ProgramTest, testFunction) { EXPECT_EQ(functionToTest(4), 8); }
|
||||||
|
TEST(ProgramTest, testFunctionShouldFail) { EXPECT_EQ(functionToTest(4), 12); }
|
||||||
|
|
||||||
|
TEST(PrepTest, testAddFunc) { EXPECT_EQ(add(4, 2), 6); }
|
||||||
Loading…
Reference in New Issue
Block a user