Skip to content

Commit

Permalink
Popravke za temu 05
Browse files Browse the repository at this point in the history
  • Loading branch information
Robotmurlock committed Nov 17, 2021
1 parent fdfc6e5 commit aa47a61
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 33 deletions.
2 changes: 1 addition & 1 deletion tema04_qt/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,4 @@ Za detaljnije objašnjene, pogledajte kod i popratne komentare u kodu.

## 03_qmake

TODO
Pogledati `03_qmake`.
Binary file removed tema05_cmake/02_hello/build/hello
Binary file not shown.
2 changes: 2 additions & 0 deletions tema05_cmake/02_hello/main.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#include <iostream>
#include <numeric>

int main()
{
std::cout << "Hello World!" << std::endl;
std::cout << std::gcd(9, 12) << std::endl;
return 0;
}
Binary file removed tema05_cmake/03_hello/Debug/hello
Binary file not shown.
Binary file removed tema05_cmake/03_hello/Release/hello
Binary file not shown.
112 changes: 82 additions & 30 deletions tema05_cmake/04_library/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,93 @@
#include <iostream>
#include <cassert>

int main()
void test_split_space()
{
// Arange
const std::string data = "hello darkness, my old friend!";
const std::string empty = "";
const std::string all_dels = "#########";
const std::string mlt_dels = "hello darkness,,, my old friend!";
const char del1 = ' ';
const char del2 = ',';
const char del3 = '#';
// Arrange
const std::string data = "hello darkness, my old friend!";
const std::vector<std::string> expected_result{"hello", "darkness,", "my", "old", "friend!"};

// Act
const std::vector<std::string> result1 = split(data, del1);;
const std::vector<std::string> result2 = split(data, del2); ;
const std::vector<std::string> result3 = split(data, del3);
const std::vector<std::string> result4 = split(empty, del2);
const std::vector<std::string> result5 = split(all_dels, del3);
const std::vector<std::string> result6 = split(mlt_dels, del2);
const auto result = split(data, ' ');

// Assert
assert(result == expected_result);
}

void test_split_comma()
{
// Arrange
const std::string data = "hello darkness, my old friend!";
const std::vector<std::string> expected_result{"hello darkness", " my old friend!"};

// Act
const auto result = split(data, ',');

// Assert
const std::vector<std::string> expected_result1 = std::vector<std::string>{"hello", "darkness,", "my", "old", "friend!"};
const std::vector<std::string> expected_result2 = std::vector<std::string>{"hello darkness", " my old friend!"};
const std::vector<std::string> expected_result3 = split(data, del3);
const std::vector<std::string> expected_result4 = split(empty, del2);
const std::vector<std::string> expected_result5 = split(all_dels, del3);
const std::vector<std::string> expected_result6 = split(mlt_dels, del2);

assert(result1 == expected_result1);
assert(result2 == expected_result2);
assert(result3 == std::vector<std::string>{"hello darkness, my old friend!"});
assert(result4 == std::vector<std::string>{});
assert(result5 == std::vector<std::string>{});
assert(result6 == std::vector<std::string>{"hello darkness", " my old friend!"});
assert(result == expected_result);
}

std::cout << "Tests passed!" << std::endl;
void test_split_hash()
{
// Arrange
const std::string data = "hello darkness, my old friend!";
const std::vector<std::string> expected_result{"hello darkness, my old friend!"};

// Act
const auto result = split(data, '#');

// Assert
assert(result == expected_result);
}

void test_split_empty()
{
// Arrange
const std::string empty = "";
const std::vector<std::string> expected_result{};

// Act
const auto result = split(empty, ' ');

// Assert
assert(result == expected_result);
}

void test_split_all_hash()
{
// Arrange
const std::string hashes = "#################";
const std::vector<std::string> expected_result{};

// Act
const auto result = split(hashes, '#');

// Assert
assert(result == expected_result);
}

void test_split_multiple_commas()
{
// Arrange
const std::string data = "hello darkness,,, my old friend!";
const std::vector<std::string> expected_result{"hello darkness", " my old friend!"};

// Act
const auto result = split(data, ',');

// Assert
assert(result == expected_result);
}

int main()
{
test_split_space();
test_split_comma();
test_split_hash();
test_split_empty();
test_split_all_hash();
test_split_multiple_commas();

std::cout << "Tests passed!" << std::endl;
return 0;
}
}
12 changes: 10 additions & 2 deletions tema05_cmake/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ Naš `HelloWorld` program je modifikovan:
int main()
{
std::cout << "Hello World!" << std::endl;
std::cout << gcd(9, 12) << std::endl;
std::cout << std::gcd(9, 12) << std::endl;
return 0;
}
```
Expand Down Expand Up @@ -157,11 +157,19 @@ set(CMAKE_CXX_FLAGS_RELEASE_INIT "-O2")
add_executable(hello main.cpp)
```

**Build:**

- `mkdir [build]`
- `cd [build]`
- `cmake -DCMAKE_BUILD_TYPE=[build] -G "Unix Makefiles" ..`
- `make`

## Biblioteka (04_library)

Želimo da napravimo biblioteku za rad sa niskama u `C++`-u. Standardna biblioteka nam već nudi `string`
klasu sa funkcijama i metodama za rad sa niskama, ali postoje neke funkcije koje su nam bitne, ali se tu ne nalaze. Jedna veoma korisna f-ja, koja nije implementirana u okviru standardne biblioteke je `split` funkcija, koja prima dva argumenta: nisku i karakter razdvajanja `delimiter` i vraća niz niski razdvojenih
klasu sa funkacijama i metodama za rad sa niskama, ali postoje neke funkcije koje su nam bitne, ali se tu ne nalaze. Jedna veoma korisna f-ja, koja nije implementirana u okviru standardne biblioteke je `split` funkcija, koja prima dva argumenta: nisku i karakter razdvajanja `delimiter` i vraća niz niski razdvojenih
po tom specijalnom karakteru. Primer:

- `split("Ahoy there matey!", ' ') = ["Ahoy", "there", "matey"]`
- `split("123,456,789", ',') = ["123", "456", "789"]`

Expand Down

0 comments on commit aa47a61

Please sign in to comment.