Skip to content

Commit

Permalink
Merge branch 'dev-mikemirzayanov' of https://github.com/MikeMirzayano…
Browse files Browse the repository at this point in the history
…v/testlib into dev-mikemirzayanov
  • Loading branch information
MikeMirzayanov committed Sep 29, 2023
2 parents 284254d + 8fa873c commit 02adee7
Show file tree
Hide file tree
Showing 21 changed files with 202 additions and 30 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -176,21 +176,21 @@ jobs:
matrix:
os: [macos-12]
compiler: [g++]
name: Use ${{ matrix.compiler }} on ${{ matrix.os }}
version: [11, 12, 13]
name: Use ${{ matrix.compiler }}-${{ matrix.version }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- name: Run tests
run: |
cd tests
bash ./run.sh ${{ matrix.compiler }}
bash ./run.sh ${{ matrix.compiler }} v${{ matrix.version }}
tests-macos12-clang:
strategy:
matrix:
os: [macos-12]
compiler: [clang++]
version: [12, 13, 14]
name: Use ${{ matrix.compiler }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
steps:
Expand All @@ -205,7 +205,7 @@ jobs:
matrix:
os: [macos-13]
compiler: [g++]
version: [11, 12]
version: [11, 12, 13]
name: Use ${{ matrix.compiler }}-${{ matrix.version }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
steps:
Expand Down
19 changes: 11 additions & 8 deletions testlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ const char *latestFeatures[] = {
#include <map>
#include <set>
#include <cmath>
#include <iterator>
#include <iostream>
#include <sstream>
#include <fstream>
Expand Down Expand Up @@ -901,7 +902,6 @@ class random_t {
int size = int(c.size());
if (size <= 0)
__testlib_fail("random_t::any(const Container& c): c.size() must be positive");
//return *(c.begin() + next(size));
typename Container::const_iterator it = c.begin();
std::advance(it, next(size));
return *it;
Expand All @@ -910,10 +910,9 @@ class random_t {
/* Returns random element from iterator range. */
template<typename Iter>
typename Iter::value_type any(const Iter &begin, const Iter &end) {
int size = int(end - begin);
int size = static_cast<int>(std::distance(begin, end));
if (size <= 0)
__testlib_fail("random_t::any(const Iter& begin, const Iter& end): range must have positive length");
// return *(begin + next(size));
Iter it = begin;
std::advance(it, next(size));
return *it;
Expand Down Expand Up @@ -1102,20 +1101,24 @@ class random_t {
/* Returns weighted random element from container. */
template<typename Container>
typename Container::value_type wany(const Container &c, int type) {
size_t size = c.size();
int size = int(c.size());
if (size <= 0)
__testlib_fail("random_t::wany(const Container& c, int type): c.size() must be positive");
return *(c.begin() + wnext(size, type));
typename Container::const_iterator it = c.begin();
std::advance(it, wnext(size, type));
return *it;
}

/* Returns weighted random element from iterator range. */
template<typename Iter>
typename Iter::value_type wany(const Iter &begin, const Iter &end, int type) {
int size = int(end - begin);
int size = static_cast<int>(std::distance(begin, end));
if (size <= 0)
__testlib_fail(
"random_t::any(const Iter& begin, const Iter& end, int type): range must have positive length");
return *(begin + wnext(size, type));
Iter it = begin;
std::advance(it, wnext(size, type));
return *it;
}

/* Returns random permutation of the given size (values are between `first` and `first`+size-1)*/
Expand Down Expand Up @@ -4401,7 +4404,7 @@ void registerGen(int argc, char *argv[]) {
}
#endif

static void setAppesModeEncoding(std::string appesModeEncoding) {
void setAppesModeEncoding(std::string appesModeEncoding) {
static const char* const ENCODINGS[] = {"ascii", "utf-7", "utf-8", "utf-16", "utf-16le", "utf-16be", "utf-32", "utf-32le", "utf-32be", "iso-8859-1",
"iso-8859-2", "iso-8859-3", "iso-8859-4", "iso-8859-5", "iso-8859-6", "iso-8859-7", "iso-8859-8", "iso-8859-9", "iso-8859-10", "iso-8859-11",
"iso-8859-13", "iso-8859-14", "iso-8859-15", "iso-8859-16", "windows-1250", "windows-1251", "windows-1252", "windows-1253", "windows-1254", "windows-1255",
Expand Down
7 changes: 5 additions & 2 deletions tests/docker/clang-11/run.bat
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
"C:\Program Files\Docker\Docker"\DockerCli.exe -SwitchLinuxEngine
@echo off

docker run -it test-testlib-clang-11
SET IMAGE_NAME=test-testlib-clang-11
for /f "tokens=*" %%i in ('git rev-parse --abbrev-ref HEAD') do set CURRENT_BRANCH=%%i

"C:\Program Files\Docker\Docker"\DockerCli.exe -SwitchLinuxEngine
docker run -it %IMAGE_NAME% /bin/bash /startup.sh %CURRENT_BRANCH%
9 changes: 7 additions & 2 deletions tests/docker/clang-11/startup.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
#!/bin/bash
set -e -o pipefail

CPP_STANDARD=14

BRANCH=${1:-dev-mikemirzayanov}
echo "Use branch ""$BRANCH"""

git clone https://github.com/MikeMirzayanov/testlib.git
cd testlib
git checkout dev-mikemirzayanov
git checkout "$BRANCH"
cd tests
./run.sh v0 11
./run.sh clang++ v0 "$CPP_STANDARD"
cd /
rm -rf testlib
7 changes: 7 additions & 0 deletions tests/docker/clang-3.5/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM silkeh/clang:3.5
RUN apt-get update
RUN apt-get install -y git default-jre
COPY startup.sh /
WORKDIR /
RUN chmod +x /startup.sh
CMD ["/bin/bash", "/startup.sh"]
4 changes: 4 additions & 0 deletions tests/docker/clang-3.5/build.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"C:\Program Files\Docker\Docker"\DockerCli.exe -SwitchLinuxEngine

docker build . -t test-testlib-clang-3.5

7 changes: 7 additions & 0 deletions tests/docker/clang-3.5/run.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@echo off

SET IMAGE_NAME=test-testlib-clang-3.5
for /f "tokens=*" %%i in ('git rev-parse --abbrev-ref HEAD') do set CURRENT_BRANCH=%%i

"C:\Program Files\Docker\Docker"\DockerCli.exe -SwitchLinuxEngine
docker run -it %IMAGE_NAME% /bin/bash /startup.sh %CURRENT_BRANCH%
15 changes: 15 additions & 0 deletions tests/docker/clang-3.5/startup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash
set -e -o pipefail

CPP_STANDARD=11

BRANCH=${1:-dev-mikemirzayanov}
echo "Use branch ""$BRANCH"""

git clone https://github.com/MikeMirzayanov/testlib.git
cd testlib
git checkout "$BRANCH"
cd tests
./run.sh clang++ v0 "$CPP_STANDARD"
cd /
rm -rf testlib
7 changes: 7 additions & 0 deletions tests/docker/clang-7/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM silkeh/clang:7
RUN apt-get update
RUN apt-get install -y git default-jre
COPY startup.sh /
WORKDIR /
RUN chmod +x /startup.sh
CMD ["/bin/bash", "/startup.sh"]
4 changes: 4 additions & 0 deletions tests/docker/clang-7/build.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"C:\Program Files\Docker\Docker"\DockerCli.exe -SwitchLinuxEngine

docker build . -t test-testlib-clang-7

7 changes: 7 additions & 0 deletions tests/docker/clang-7/run.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@echo off

SET IMAGE_NAME=test-testlib-clang-7
for /f "tokens=*" %%i in ('git rev-parse --abbrev-ref HEAD') do set CURRENT_BRANCH=%%i

"C:\Program Files\Docker\Docker"\DockerCli.exe -SwitchLinuxEngine
docker run -it %IMAGE_NAME% /bin/bash /startup.sh %CURRENT_BRANCH%
15 changes: 15 additions & 0 deletions tests/docker/clang-7/startup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash
set -e -o pipefail

CPP_STANDARD=11

BRANCH=${1:-dev-mikemirzayanov}
echo "Use branch ""$BRANCH"""

git clone https://github.com/MikeMirzayanov/testlib.git
cd testlib
git checkout "$BRANCH"
cd tests
./run.sh clang++ v0 "$CPP_STANDARD"
cd /
rm -rf testlib
7 changes: 5 additions & 2 deletions tests/docker/clang-latest/run.bat
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
"C:\Program Files\Docker\Docker"\DockerCli.exe -SwitchLinuxEngine
@echo off

docker run -it test-testlib-clang-latest
SET IMAGE_NAME=test-testlib-clang-latest
for /f "tokens=*" %%i in ('git rev-parse --abbrev-ref HEAD') do set CURRENT_BRANCH=%%i

"C:\Program Files\Docker\Docker"\DockerCli.exe -SwitchLinuxEngine
docker run -it %IMAGE_NAME% /bin/bash /startup.sh %CURRENT_BRANCH%
9 changes: 7 additions & 2 deletions tests/docker/clang-latest/startup.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
#!/bin/bash
set -e -o pipefail

CPP_STANDARD=20

BRANCH=${1:-dev-mikemirzayanov}
echo "Use branch ""$BRANCH"""

git clone https://github.com/MikeMirzayanov/testlib.git
cd testlib
git checkout dev-mikemirzayanov
git checkout "$BRANCH"
cd tests
./run.sh v0 23
./run.sh clang++ v0 "$CPP_STANDARD"
cd /
rm -rf testlib
7 changes: 5 additions & 2 deletions tests/docker/gcc-7/run.bat
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
"C:\Program Files\Docker\Docker"\DockerCli.exe -SwitchLinuxEngine
@echo off

docker run -it test-testlib-gcc-7
SET IMAGE_NAME=test-testlib-gcc-7
for /f "tokens=*" %%i in ('git rev-parse --abbrev-ref HEAD') do set CURRENT_BRANCH=%%i

"C:\Program Files\Docker\Docker"\DockerCli.exe -SwitchLinuxEngine
docker run -it %IMAGE_NAME% /bin/bash /startup.sh %CURRENT_BRANCH%
9 changes: 7 additions & 2 deletions tests/docker/gcc-7/startup.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
#!/bin/bash
set -e -o pipefail

CPP_STANDARD=11

BRANCH=${1:-dev-mikemirzayanov}
echo "Use branch ""$BRANCH"""

git clone https://github.com/MikeMirzayanov/testlib.git
cd testlib
git checkout dev-mikemirzayanov
git checkout "$BRANCH"
cd tests
./run.sh g++ v0 11
./run.sh g++ v0 "$CPP_STANDARD"
cd /
rm -rf testlib
11 changes: 7 additions & 4 deletions tests/docker/gcc-latest/run.bat
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
"C:\Program Files\Docker\Docker"\DockerCli.exe -SwitchLinuxEngine

docker run -it test-testlib-gcc-latest

@echo off

SET IMAGE_NAME=test-testlib-gcc-latest
for /f "tokens=*" %%i in ('git rev-parse --abbrev-ref HEAD') do set CURRENT_BRANCH=%%i

"C:\Program Files\Docker\Docker"\DockerCli.exe -SwitchLinuxEngine
docker run -it %IMAGE_NAME% /bin/bash /startup.sh %CURRENT_BRANCH%
9 changes: 7 additions & 2 deletions tests/docker/gcc-latest/startup.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
#!/bin/bash
set -e -o pipefail

CPP_STANDARD=23

BRANCH=${1:-dev-mikemirzayanov}
echo "Use branch ""$BRANCH"""

git clone https://github.com/MikeMirzayanov/testlib.git
cd testlib
git checkout dev-mikemirzayanov
git checkout "$BRANCH"
cd tests
./run.sh g++ v0 23
./run.sh g++ v0 "$CPP_STANDARD"
cd /
rm -rf testlib
15 changes: 15 additions & 0 deletions tests/test-003_run-rnd/refs/r1/stdout
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,18 @@ vutwaahqooeqoxzxwetlpecqiwgdbogiqqulttysyohwhzxzphvsfmnplizxoebzcvvfyppqbhxjksuz
1880
1973
1850
2116
441
e
a
c
f
e
d
b
f
c
f
f
b
b
15 changes: 15 additions & 0 deletions tests/test-003_run-rnd/refs/r2/stdout
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,18 @@ clizwkchataumicxkohcrpqnyrjyzbjvsypznpembvkkkbyzvzckcmhbjbuopfbwbkntswhwsdfzabjg
1363
1897
1175
3249
3481
e
d
c
f
d
a
a
e
e
f
f
d
c
41 changes: 41 additions & 0 deletions tests/test-003_run-rnd/src/gen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,45 @@ int main(int argc, char* argv[])
std::cout << rnd.wnext((signed long long) 42, (signed long long) 2011, 4) << std::endl;
std::cout << rnd.wnext((signed int) 42, (signed int) 2011, 4) << std::endl;
std::cout << rnd.wnext((signed short) 42, (signed short) 2011, 4) << std::endl;

println(rnd.wany(a, 1));
println(rnd.wany(a, -1));

set<string> b;
b.insert("a"); b.insert("b"); b.insert("c"); b.insert("d"); b.insert("e"); b.insert("f"); b.insert("g");
println(rnd.any(b));

{
std::set<std::string> string_set;
string_set.insert("a");
string_set.insert("b");
string_set.insert("c");
string_set.insert("d");
string_set.insert("e");
string_set.insert("f");

std::cout << rnd.any(string_set) << std::endl;
std::cout << rnd.any(string_set.begin(), string_set.end()) << std::endl;
std::cout << rnd.wany(string_set, 1) << std::endl;
std::cout << rnd.wany(string_set.begin(), string_set.end(), 1) << std::endl;
std::cout << rnd.wany(string_set, -1) << std::endl;
std::cout << rnd.wany(string_set.begin(), string_set.end(), -1) << std::endl;
}

{
std::multiset<std::string> string_multiset;
string_multiset.insert("a");
string_multiset.insert("b"); string_multiset.insert("b");
string_multiset.insert("c"); string_multiset.insert("c"); string_multiset.insert("c");
string_multiset.insert("d");
string_multiset.insert("e"); string_multiset.insert("e"); string_multiset.insert("e");
string_multiset.insert("f"); string_multiset.insert("f"); string_multiset.insert("f"); string_multiset.insert("f");

std::cout << rnd.any(string_multiset) << std::endl;
std::cout << rnd.any(string_multiset.begin(), string_multiset.end()) << std::endl;
std::cout << rnd.wany(string_multiset, 2) << std::endl;
std::cout << rnd.wany(string_multiset.begin(), string_multiset.end(), 1) << std::endl;
std::cout << rnd.wany(string_multiset, -1) << std::endl;
std::cout << rnd.wany(string_multiset.begin(), string_multiset.end(), -2) << std::endl;
}
}

0 comments on commit 02adee7

Please sign in to comment.