Skip to content

Commit

Permalink
added test
Browse files Browse the repository at this point in the history
  • Loading branch information
telatin committed Sep 18, 2024
1 parent 6819e49 commit d91e735
Show file tree
Hide file tree
Showing 7 changed files with 161 additions and 0 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/test_n50.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: N50 Calculator CI

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
workflow_dispatch:

jobs:
build-and-test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y gcc make zlib1g-dev
- name: Build N50 Calculator
run: make

- name: Run tests
run: make test

- name: Run simple test
run: make test-simple

- name: Archive binary
uses: actions/upload-artifact@v2
with:
name: n50-calculator
path: bin/n50
66 changes: 66 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
CC = gcc
CFLAGS = -Wall -Wextra -O3
LDFLAGS = -lz -lpthread

SRC_DIR = src
BIN_DIR = bin
TEST_DIR = test
TARGET = $(BIN_DIR)/n50

.PHONY: all clean test

all: $(TARGET)

$(TARGET): $(SRC_DIR)/n50.c | $(BIN_DIR)
$(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)

$(BIN_DIR):
mkdir -p $(BIN_DIR)

clean:
rm -rf $(BIN_DIR)

test: $(TARGET)
@echo "Running tests..."
@passed=0; failed=0; \
for file in $(TEST_DIR)/*.*; do \
filename=$$(basename $$file); \
expected_n50=$${filename%%.*}; \
echo "Testing $$filename (Expected N50: $$expected_n50)"; \
output=$$($(TARGET) $$file); \
actual_n50=$$(echo "$$output" | cut -f4); \
if [ "$$actual_n50" = "$$expected_n50" ]; then \
echo " Passed"; \
passed=$$((passed + 1)); \
else \
echo " Failed. Expected N50: $$expected_n50, Got: $$actual_n50"; \
failed=$$((failed + 1)); \
fi; \
done; \
echo "Tests completed. Passed: $$passed, Failed: $$failed"; \
if [ $$failed -ne 0 ]; then exit 1; fi

# Original simple test
test-simple: $(TARGET)
@echo "Running simple test..."
@echo ">seq1" > test.fasta
@echo "ATCGATCGATCG" >> test.fasta
@echo ">seq2" >> test.fasta
@echo "ATCGATCGATCGATCGATCG" >> test.fasta
@echo ">seq3" >> test.fasta
@echo "ATCG" >> test.fasta
@output=$$($(TARGET) test.fasta); \
echo "Output: $$output"; \
total_bp=$$(echo "$$output" | cut -f2); \
total_seq=$$(echo "$$output" | cut -f3); \
n50=$$(echo "$$output" | cut -f4); \
if [ "$$total_bp" = "36" ] && [ "$$total_seq" = "3" ] && [ "$$n50" = "20" ]; then \
echo "Simple test passed successfully!"; \
else \
echo "Simple test failed!"; \
echo "Expected: 36 total bp, 3 sequences, N50 of 20"; \
echo "Got: $$total_bp total bp, $$total_seq sequences, N50 of $$n50"; \
exit 1; \
fi
@rm test.fasta
@echo "Simple test completed."
Binary file added bin/n50
Binary file not shown.
20 changes: 20 additions & 0 deletions test/54.fa
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
>Seq1 Description
GATACTGACTGACTGATCGATCGTAGCTAGCTAGCTGATCTAGCTAGCTAGCTA
>Seq2 Description
GACTGATCGATCGTAGCTA
>Seq3 Description
GATACTGACTGACTGATCGATCGTAGCTAGCTAGCTGATCTAGCTAGCTAGCTA
>Seq4 Description
GACTGATCGATCGTAGCTA
>Seq5 Description
GATACTGACTGACTGATCGATCGTAGCTAGCTAGCTGATCTAGCTAGCTAGCTA
>Seq6 Description
GACTGATCGATCGTAGCTA
>Seq7 Description
GATACTGAGAGTATATACACACACGACTGACTGATCGATCGTAGCTAGCTAGCTGATCTAGCTAGCTAGCTA
>Seq8 Description
GACTGATCGATCGTAGCTA
>Seq9 Description
GATACTCTGATCGATCGTAGCTAGCTAGCTGATCTAGCTAGCTAGCTA
>Seq10 Description
GACTGATCGATCGTAGCTA
Binary file added test/54.fa.gz
Binary file not shown.
40 changes: 40 additions & 0 deletions test/54.fq
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
@Seq1 Description
GATACTGACTGACTGATCGATCGTAGCTAGCTAGCTGATCTAGCTAGCTAGCTA
+
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
@Seq2 Description
GACTGATCGATCGTAGCTA
+
BBBBBBBBBBBBBBBBBBB
@Seq3 Description
GATACTGACTGACTGATCGATCGTAGCTAGCTAGCTGATCTAGCTAGCTAGCTA
+
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
@Seq4 Description
GACTGATCGATCGTAGCTA
+
BBBBBBBBBBBBBBBBBBB
@Seq5 Description
GATACTGACTGACTGATCGATCGTAGCTAGCTAGCTGATCTAGCTAGCTAGCTA
+
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
@Seq6 Description
GACTGATCGATCGTAGCTA
+
BBBBBBBBBBBBBBBBBBB
@Seq7 Description
GATACTGAGAGTATATACACACACGACTGACTGATCGATCGTAGCTAGCTAGCTGATCTAGCTAGCTAGCTA
+
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
@Seq8 Description
GACTGATCGATCGTAGCTA
+
BBBBBBBBBBBBBBBBBBB
@Seq9 Description
GATACTCTGATCGATCGTAGCTAGCTAGCTGATCTAGCTAGCTAGCTA
+
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
@Seq10 Description
GACTGATCGATCGTAGCTA
+
BBBBBBBBBBBBBBBBBBB
Binary file added test/54.fq.gz
Binary file not shown.

0 comments on commit d91e735

Please sign in to comment.