Skip to content

Commit

Permalink
refactor shell scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
Nenad committed Jun 20, 2024
1 parent e144a0f commit 1a88f5a
Show file tree
Hide file tree
Showing 46 changed files with 651 additions and 26 deletions.
39 changes: 24 additions & 15 deletions bin/format_exercises.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,41 @@ repo=$(git rev-parse --show-toplevel)
# traverse either concept or practice exercise
# directory and format Cairo files
format_exercises() {
exercises_path="$repo/exercises/$1"
exercises_path="$repo/exercises/$1/*"
source_file_name="$2"
for exercise_dir in "$exercises_path"/*; do
cd "$exercise_dir"

for exercise_dir in $exercises_path; do
cd "$exercise_dir" || exit 1

exercise=$(basename "$exercise_dir")

# scarb fmt cannot currently format individual files, so we have to
# temporarily move the solution files into the Cairo package, where
# 'scarb fmt' can format it as well
tmp_file=$(mktemp "./src/tmp.XXXXXXXXXXX.cairo")
trap 'rm -rf $tmp_dir' EXIT INT TERM

config_file="$exercise_dir/.meta/config.json"
if jq --exit-status '.custom?."allowed-to-not-compile"?' "$config_file"; then
exercise=$(basename "$exercise_dir")
echo "$exercise's stub is allowed to not compile"
# exit the subshell successfully to continue
# to the next exercise directory
exit 0
fi
# scarb fmt cannot currently format individual files, so we have to
# temporarily move the solution files into the Cairo package, where
# 'scarb fmt' can format it as well
tmp_file=$(mktemp "./src/tmp.XXXXXXXXXXX.cairo")
file_name=".meta/$source_file_name.cairo"
if [ -f "$file_name" ]; then
cp "$file_name" "$tmp_file"

solution_file=".meta/$source_file_name.cairo"
if [ -z "$solution_file" ]; then
echo "Could not find solution file for $exercise"
exit 1
fi

# move the solution file into the package
cp "$solution_file" "$tmp_file"

scarb fmt

# move the solution file back
if [ -f "$file_name" ]; then
cp "$tmp_file" "$file_name"
fi
rm $tmp_file
cp "$tmp_file" "$solution_file"
done
}

Expand Down
22 changes: 11 additions & 11 deletions bin/verify-exercises
Original file line number Diff line number Diff line change
Expand Up @@ -19,33 +19,33 @@ verify_exercise() {
exercises_path="$repo/exercises/$1/$slug"
source_file_name="$2"
tmp_file=$(mktemp)

trap 'rm -rf $tmp_dir' EXIT INT TERM

for exercise_dir in $exercises_path; do
if [ -z "$exercise_dir" ]; then
continue
fi

echo "Checking $(basename "$exercise_dir") exercise..."


exercise=$(basename "$exercise_dir")
echo "Checking $exercise exercise..."

cd "$exercise_dir" || exit 1

solution_file=".meta/$source_file_name.cairo"
if [ -z "$solution_file" ]; then
echo "Could not find solution for $1"
echo "Could not find solution file for $exercise"
exit 1
fi

# since we're testing the solution, we need to temporarily replace
# the exercise's solution files with its exemplar/example files
cp "$lib_cairo" "$tmp_file"
cp "$solution_file" "$lib_cairo"

scarb cairo-test

cp "$tmp_file" "$lib_cairo"
done

rm "$tmp_file"
}

# https://github.com/exercism/docs/blob/main/anatomy/tracks/concept-exercises.md#file-exemplar-implementation
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use alexandria_math::armstrong_number;

fn is_armstrong_number(num: u32) -> bool {
armstrong_number::is_armstrong_number(num.into())
}

#[cfg(test)]
mod tests;
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use alexandria_math::armstrong_number;

fn is_armstrong_number(num: u32) -> bool {
armstrong_number::is_armstrong_number(num.into())
}

#[cfg(test)]
mod tests;
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use alexandria_math::armstrong_number;

fn is_armstrong_number(num: u32) -> bool {
armstrong_number::is_armstrong_number(num.into())
}

#[cfg(test)]
mod tests;
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use alexandria_math::armstrong_number;

fn is_armstrong_number(num: u32) -> bool {
armstrong_number::is_armstrong_number(num.into())
}

#[cfg(test)]
mod tests;
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use alexandria_math::armstrong_number;

fn is_armstrong_number(num: u32) -> bool {
armstrong_number::is_armstrong_number(num.into())
}

#[cfg(test)]
mod tests;
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use alexandria_math::armstrong_number;

fn is_armstrong_number(num: u32) -> bool {
armstrong_number::is_armstrong_number(num.into())
}

#[cfg(test)]
mod tests;
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use alexandria_math::armstrong_number;

fn is_armstrong_number(num: u32) -> bool {
armstrong_number::is_armstrong_number(num.into())
}

#[cfg(test)]
mod tests;
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use alexandria_math::armstrong_number;

fn is_armstrong_number(num: u32) -> bool {
armstrong_number::is_armstrong_number(num.into())
}

#[cfg(test)]
mod tests;
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use alexandria_math::armstrong_number;

fn is_armstrong_number(num: u32) -> bool {
armstrong_number::is_armstrong_number(num.into())
}

#[cfg(test)]
mod tests;
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use alexandria_math::armstrong_number;

fn is_armstrong_number(num: u32) -> bool {
armstrong_number::is_armstrong_number(num.into())
}

#[cfg(test)]
mod tests;
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use alexandria_math::armstrong_number;

fn is_armstrong_number(num: u32) -> bool {
armstrong_number::is_armstrong_number(num.into())
}

#[cfg(test)]
mod tests;
7 changes: 7 additions & 0 deletions exercises/practice/hello-world/src/tmp.5yJVH9QODZC.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
fn hello() -> felt252 {
'Hello, World!'
}

#[cfg(test)]
mod tests;

7 changes: 7 additions & 0 deletions exercises/practice/hello-world/src/tmp.AK50pREsXJk.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
fn hello() -> felt252 {
'Hello, World!'
}

#[cfg(test)]
mod tests;

7 changes: 7 additions & 0 deletions exercises/practice/hello-world/src/tmp.HQuiDllRSzQ.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
fn hello() -> felt252 {
'Hello, World!'
}

#[cfg(test)]
mod tests;

7 changes: 7 additions & 0 deletions exercises/practice/hello-world/src/tmp.ag3tlMqcVET.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
fn hello() -> felt252 {
'Hello, World!'
}

#[cfg(test)]
mod tests;

7 changes: 7 additions & 0 deletions exercises/practice/hello-world/src/tmp.dYc3X0pkNIr.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
fn hello() -> felt252 {
'Hello, World!'
}

#[cfg(test)]
mod tests;

7 changes: 7 additions & 0 deletions exercises/practice/hello-world/src/tmp.gBw8UOwm8RX.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
fn hello() -> felt252 {
'Hello, World!'
}

#[cfg(test)]
mod tests;

7 changes: 7 additions & 0 deletions exercises/practice/hello-world/src/tmp.i0VoAkMxKiG.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
fn hello() -> felt252 {
'Hello, World!'
}

#[cfg(test)]
mod tests;

7 changes: 7 additions & 0 deletions exercises/practice/hello-world/src/tmp.i7SQCGjYvPM.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
fn hello() -> felt252 {
'Hello, World!'
}

#[cfg(test)]
mod tests;

7 changes: 7 additions & 0 deletions exercises/practice/hello-world/src/tmp.jilCNYlo8Ei.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
fn hello() -> felt252 {
'Hello, World!'
}

#[cfg(test)]
mod tests;

7 changes: 7 additions & 0 deletions exercises/practice/hello-world/src/tmp.oQm8nW4CXw3.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
fn hello() -> felt252 {
'Hello, World!'
}

#[cfg(test)]
mod tests;

7 changes: 7 additions & 0 deletions exercises/practice/hello-world/src/tmp.rSQDZnqBOaA.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
fn hello() -> felt252 {
'Hello, World!'
}

#[cfg(test)]
mod tests;

10 changes: 10 additions & 0 deletions exercises/practice/leap/src/tmp.0nHbl07Mvpk.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
fn is_leap_year(year: u64) -> bool {
has_factor(year, 4) && (!has_factor(year, 100) || has_factor(year, 400))
}

fn has_factor(year: u64, factor: u64) -> bool {
year % factor == 0
}

#[cfg(test)]
mod tests;
10 changes: 10 additions & 0 deletions exercises/practice/leap/src/tmp.4JcB7ytQzPP.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
fn is_leap_year(year: u64) -> bool {
has_factor(year, 4) && (!has_factor(year, 100) || has_factor(year, 400))
}

fn has_factor(year: u64, factor: u64) -> bool {
year % factor == 0
}

#[cfg(test)]
mod tests;
10 changes: 10 additions & 0 deletions exercises/practice/leap/src/tmp.9JJMVbfE9Gs.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
fn is_leap_year(year: u64) -> bool {
has_factor(year, 4) && (!has_factor(year, 100) || has_factor(year, 400))
}

fn has_factor(year: u64, factor: u64) -> bool {
year % factor == 0
}

#[cfg(test)]
mod tests;
10 changes: 10 additions & 0 deletions exercises/practice/leap/src/tmp.IJV3mLxjN0L.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
fn is_leap_year(year: u64) -> bool {
has_factor(year, 4) && (!has_factor(year, 100) || has_factor(year, 400))
}

fn has_factor(year: u64, factor: u64) -> bool {
year % factor == 0
}

#[cfg(test)]
mod tests;
10 changes: 10 additions & 0 deletions exercises/practice/leap/src/tmp.KdpoYJgsX7L.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
fn is_leap_year(year: u64) -> bool {
has_factor(year, 4) && (!has_factor(year, 100) || has_factor(year, 400))
}

fn has_factor(year: u64, factor: u64) -> bool {
year % factor == 0
}

#[cfg(test)]
mod tests;
10 changes: 10 additions & 0 deletions exercises/practice/leap/src/tmp.WgImDbYauxL.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
fn is_leap_year(year: u64) -> bool {
has_factor(year, 4) && (!has_factor(year, 100) || has_factor(year, 400))
}

fn has_factor(year: u64, factor: u64) -> bool {
year % factor == 0
}

#[cfg(test)]
mod tests;
10 changes: 10 additions & 0 deletions exercises/practice/leap/src/tmp.Y9inCbSsh6k.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
fn is_leap_year(year: u64) -> bool {
has_factor(year, 4) && (!has_factor(year, 100) || has_factor(year, 400))
}

fn has_factor(year: u64, factor: u64) -> bool {
year % factor == 0
}

#[cfg(test)]
mod tests;
10 changes: 10 additions & 0 deletions exercises/practice/leap/src/tmp.hZpdC0NpJht.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
fn is_leap_year(year: u64) -> bool {
has_factor(year, 4) && (!has_factor(year, 100) || has_factor(year, 400))
}

fn has_factor(year: u64, factor: u64) -> bool {
year % factor == 0
}

#[cfg(test)]
mod tests;
10 changes: 10 additions & 0 deletions exercises/practice/leap/src/tmp.wHN8WLzNzAU.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
fn is_leap_year(year: u64) -> bool {
has_factor(year, 4) && (!has_factor(year, 100) || has_factor(year, 400))
}

fn has_factor(year: u64, factor: u64) -> bool {
year % factor == 0
}

#[cfg(test)]
mod tests;
10 changes: 10 additions & 0 deletions exercises/practice/leap/src/tmp.xmVOE3LsKfe.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
fn is_leap_year(year: u64) -> bool {
has_factor(year, 4) && (!has_factor(year, 100) || has_factor(year, 400))
}

fn has_factor(year: u64, factor: u64) -> bool {
year % factor == 0
}

#[cfg(test)]
mod tests;
Loading

0 comments on commit 1a88f5a

Please sign in to comment.