Skip to content

Commit

Permalink
added testing
Browse files Browse the repository at this point in the history
  • Loading branch information
K20shores committed Dec 17, 2023
1 parent 81b2995 commit 45619cf
Show file tree
Hide file tree
Showing 7 changed files with 168 additions and 55 deletions.
58 changes: 58 additions & 0 deletions .github/workflows/mac.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Mac

on: [push, pull_request]

concurrency:
group: ${{ github.workflow }}-${{ github.ref || github.run_id }}
cancel-in-progress: true

jobs:
xcode_macos_13:
runs-on: macos-13
strategy:
matrix:
xcode: ['14.1', '15.0']
build_type: [Debug, Release]
env:
DEVELOPER_DIR: /Applications/Xcode_${{ matrix.xcode }}.app/Contents/Developer

steps:
- uses: actions/checkout@v3

- name: Run Cmake
run: cmake -S . -B build -D CMAKE_BUILD_TYPE=${{ matrix.build_type }}

- name: Build
run: cmake --build build --parallel 10

- name: Run tests
run: |
cd build
ctest -C ${{ matrix.build_type }} --rerun-failed --output-on-failure . --verbose -j 10
macos_lateset:
runs-on: macos-latest
strategy:
matrix:
compiler:
- { cpp: g++-11, c: gcc-11}
- { cpp: g++-12, c: gcc-12}
- { cpp: clang++, c: clang}
build_type: [Debug, Release]
env:
CC: ${{ matrix.compiler.c }}
CXX: ${{ matrix.compiler.cpp }}

steps:
- uses: actions/checkout@v3

- name: Run Cmake
run: cmake -S . -B build -D CMAKE_BUILD_TYPE=${{ matrix.build_type }}

- name: Build
run: cmake --build build --parallel 10

- name: Run tests
run: |
cd build
ctest -C ${{ matrix.build_type }} --rerun-failed --output-on-failure . --verbose -j 10
54 changes: 54 additions & 0 deletions .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Ubuntu

on: [push, pull_request]

concurrency:
group: ${{ github.workflow }}-${{ github.ref || github.run_id }}
cancel-in-progress: true

jobs:
gcc:
runs-on: ubuntu-latest
strategy:
matrix:
build_type: [Debug, Release]
env:
CC: gcc
CXX: g++
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Run Cmake
run: cmake -S . -B build -D CMAKE_BUILD_TYPE=${{ matrix.build_type }}

- name: Build
run: cmake --build build --parallel 10

- name: Run tests
run: |
cd build
ctest -C ${{ matrix.build_type }} --rerun-failed --output-on-failure . --verbose -j 10
clang:
runs-on: ubuntu-latest
strategy:
matrix:
build_type: [Debug, Release]
env:
CC: clang
CXX: clang++
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Run Cmake
run: cmake -S . -B build -D CMAKE_BUILD_TYPE=${{ matrix.build_type }}

- name: Build
run: cmake --build build --verbose

- name: Run tests
run: |
cd build
ctest -C ${{ matrix.build_type }} --rerun-failed --output-on-failure . --verbose -j 10
28 changes: 28 additions & 0 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Windows

on: [push, pull_request]

concurrency:
group: ${{ github.workflow }}-${{ github.ref || github.run_id }}
cancel-in-progress: true

jobs:
msvc2022:
runs-on: windows-latest
strategy:
matrix:
build_type: [Debug, Release]
architecture: [Win32, x64]

steps:
- uses: actions/checkout@v3
- name: Run CMake
run: cmake -S . -B build -A ${{ matrix.architecture }}
if: matrix.build_type == 'Release'
- name: Run CMake
run: cmake -S . -B build -A ${{ matrix.architecture }}
if: matrix.build_type == 'Debug'
- name: Build
run: cmake --build build --config ${{ matrix.build_type }} --parallel 10
- name: Test
run: cd build ; ctest -j 10 -C ${{ matrix.build_type }} --output-on-failure
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@

![](https://img.shields.io/badge/stars%20⭐-31-yellow)
![](https://img.shields.io/badge/days%20completed-15-red)
[![Windows](https://github.com/K20shores/aoc2023/actions/workflows/windows.yml/badge.svg)](https://github.com/K20shores/aoc2023/actions/workflows/windows.yml)
[![Mac](https://github.com/K20shores/aoc2023/actions/workflows/mac.yml/badge.svg)](https://github.com/K20shores/aoc2023/actions/workflows/mac.yml)
[![Ubuntu](https://github.com/K20shores/aoc2023/actions/workflows/ubuntu.yml/badge.svg)](https://github.com/K20shores/aoc2023/actions/workflows/ubuntu.yml)

[adventofcode.com](https://adventofcode.com/2023)
3 changes: 1 addition & 2 deletions include/aoc2023/maths.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@
std::vector<int> get_primes(int n);
std::vector<int> prime_factorize(int a, const std::vector<int> &primes);
long lcm(std::vector<int> vals, const std::vector<int> &primes);
long n_choose_k(long n, long k);
long n_permute_k(long n, long k);
long n_choose_k(long n, long k);
70 changes: 24 additions & 46 deletions src/day10.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ struct Data {
};

char get_char(const std::vector<std::string> &data, Pos cur) {
if (cur.i >= 0 && cur.i < data.size() && cur.j >= 0 &&
cur.j < data[cur.i].size())
return data[cur.i][cur.j];
if (cur.i >= 0 && cur.i < data.size() && cur.j >= 0 && cur.j < data[cur.i].size()) return data[cur.i][cur.j];
return '\0';
}

Expand All @@ -38,48 +36,33 @@ std::vector<Pos> connected_pipes(const Pos &cur, const Data &data) {
switch (curc) {
case 'S':
if (upc == '7' || upc == 'F' || upc == '|') connected.push_back(up);
if (downc == 'L' || downc == 'J' || downc == '|')
connected.push_back(down);
if (leftc == 'L' || leftc == 'F' || leftc == '-')
connected.push_back(left);
if (rightc == '7' || rightc == 'J' || rightc == '-')
connected.push_back(right);
if (downc == 'L' || downc == 'J' || downc == '|') connected.push_back(down);
if (leftc == 'L' || leftc == 'F' || leftc == '-') connected.push_back(left);
if (rightc == '7' || rightc == 'J' || rightc == '-') connected.push_back(right);
break;
case '|': // is a vertical pipe connecting north and south.
if (upc == '7' || upc == 'F' || upc == '|' || upc == 'S')
connected.push_back(up);
if (downc == 'L' || downc == 'J' || downc == '|' || downc == 'S')
connected.push_back(down);
if (upc == '7' || upc == 'F' || upc == '|' || upc == 'S') connected.push_back(up);
if (downc == 'L' || downc == 'J' || downc == '|' || downc == 'S') connected.push_back(down);
break;
case '-': // is a horizontal pipe connecting east and west.
if (leftc == 'L' || leftc == 'F' || leftc == '-' || leftc == 'S')
connected.push_back(left);
if (rightc == '7' || rightc == 'J' || rightc == '-' || rightc == 'S')
connected.push_back(right);
if (leftc == 'L' || leftc == 'F' || leftc == '-' || leftc == 'S') connected.push_back(left);
if (rightc == '7' || rightc == 'J' || rightc == '-' || rightc == 'S') connected.push_back(right);
break;
case 'L': // is a 90-degree bend connecting north and east.
if (upc == '|' || upc == '7' || upc == 'F' || upc == 'S')
connected.push_back(up);
if (rightc == '7' || rightc == 'J' || rightc == '-' || rightc == 'S')
connected.push_back(right);
if (upc == '|' || upc == '7' || upc == 'F' || upc == 'S') connected.push_back(up);
if (rightc == '7' || rightc == 'J' || rightc == '-' || rightc == 'S') connected.push_back(right);
break;
case 'J': // is a 90-degree bend connecting north and west.
if (upc == '|' || upc == '7' || upc == 'F' || upc == 'S')
connected.push_back(up);
if (leftc == 'F' || leftc == '-' || leftc == 'L' || leftc == 'S')
connected.push_back(left);
if (upc == '|' || upc == '7' || upc == 'F' || upc == 'S') connected.push_back(up);
if (leftc == 'F' || leftc == '-' || leftc == 'L' || leftc == 'S') connected.push_back(left);
break;
case '7': // is a 90-degree bend connecting south and west.
if (downc == '|' || downc == 'L' || downc == 'J' || downc == 'S')
connected.push_back(down);
if (leftc == 'F' || leftc == '-' || leftc == 'L' || leftc == 'S')
connected.push_back(left);
if (downc == '|' || downc == 'L' || downc == 'J' || downc == 'S') connected.push_back(down);
if (leftc == 'F' || leftc == '-' || leftc == 'L' || leftc == 'S') connected.push_back(left);
break;
case 'F': // is a 90-degree bend connecting south and east.
if (downc == '|' || downc == 'L' || downc == 'J' || downc == 'S')
connected.push_back(down);
if (rightc == '7' || rightc == '-' || rightc == 'J' || rightc == 'S')
connected.push_back(right);
if (downc == '|' || downc == 'L' || downc == 'J' || downc == 'S') connected.push_back(down);
if (rightc == '7' || rightc == '-' || rightc == 'J' || rightc == 'S') connected.push_back(right);
break;
case '.': // is ground; there is no pipe in this tile.
throw std::runtime_error("You shouldn't be here!");
Expand Down Expand Up @@ -121,8 +104,7 @@ int part1(const Data &data) {
return steps;
}

int floodfill(const Pos &cur, Data &data, char fill_char = '0',
char loop_char = '*') {
int floodfill(const Pos &cur, Data &data, char fill_char = '0', char loop_char = '*') {
std::queue<Pos> working_set;
working_set.push(cur);
int filled = 0;
Expand All @@ -147,14 +129,13 @@ int floodfill(const Pos &cur, Data &data, char fill_char = '0',
if (upc != '*' && upc != '0' && upc != '\0') working_set.push(up);
if (downc != '*' && downc != '0' && downc != '\0') working_set.push(down);
if (leftc != '*' && leftc != '0' && leftc != '\0') working_set.push(left);
if (rightc != '*' && rightc != '0' && rightc != '\0')
working_set.push(right);
if (rightc != '*' && rightc != '0' && rightc != '\0') working_set.push(right);
}
}
return filled;
}

void replace_s(Data& data, Pos& p1, Pos& p2) {
void replace_s(Data &data, Pos &p1, Pos &p2) {
if (p1.i > p2.i) {
// p1 is above p2
if (p1.j > p2.j) {
Expand All @@ -163,25 +144,21 @@ void replace_s(Data& data, Pos& p1, Pos& p2) {
} else if (p1.j < p2.j) {
// and to the left
data.pipes[data.S.i][data.S.j] = '7';
}
else {
} else {
data.pipes[data.S.i][data.S.j] = '|';
}
}
else if (p1.i < p2.i) {
} else if (p1.i < p2.i) {
// p1 is below p2
if (p1.j > p2.j) {
// and to the right
data.pipes[data.S.i][data.S.j] = 'L';
} else if (p1.j < p2.j) {
// and to the left
data.pipes[data.S.i][data.S.j] = 'J';
}
else {
} else {
data.pipes[data.S.i][data.S.j] = '|';
}
}
else {
} else {
// same line
data.pipes[data.S.i][data.S.j] = '-';
}
Expand Down Expand Up @@ -274,6 +251,7 @@ int part2(Data data) {
region = Case::Out;
break;
default:
break;
}
}
}
Expand Down
7 changes: 0 additions & 7 deletions src/lib/maths.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,4 @@ long n_choose_k(long n, long k)
result = result / i * n + result % i * n / i;
}
return result;
}

long n_permute_k(long n, long k) {
long result = 1;
for(size_t i = 0; i <= k; ++i) {
result *= (n - i);
}
}

0 comments on commit 45619cf

Please sign in to comment.