From d91e7358008dce3cdaa896721465fedc697be586 Mon Sep 17 00:00:00 2001 From: Andrea Telatin <15690844+telatin@users.noreply.github.com> Date: Wed, 18 Sep 2024 15:02:49 +0100 Subject: [PATCH] added test --- .github/workflows/test_n50.yml | 35 +++++++++++++++++ Makefile | 66 +++++++++++++++++++++++++++++++++ bin/n50 | Bin 0 -> 18312 bytes test/54.fa | 20 ++++++++++ test/54.fa.gz | Bin 0 -> 113 bytes test/54.fq | 40 ++++++++++++++++++++ test/54.fq.gz | Bin 0 -> 128 bytes 7 files changed, 161 insertions(+) create mode 100644 .github/workflows/test_n50.yml create mode 100644 Makefile create mode 100755 bin/n50 create mode 100644 test/54.fa create mode 100644 test/54.fa.gz create mode 100644 test/54.fq create mode 100644 test/54.fq.gz diff --git a/.github/workflows/test_n50.yml b/.github/workflows/test_n50.yml new file mode 100644 index 0000000..3f41cdc --- /dev/null +++ b/.github/workflows/test_n50.yml @@ -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 diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..1604da7 --- /dev/null +++ b/Makefile @@ -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." diff --git a/bin/n50 b/bin/n50 new file mode 100755 index 0000000000000000000000000000000000000000..4354e55d7bc52b06f7010a30447f3049780eea8f GIT binary patch literal 18312 zcmeHPdvIITnLo1ZL`fXUKvDt(q6Vd#6fEqJgqRS}O|0Y!ln@ddD6eZpk{^pLInq^| zq&!UJQ0@vXW}w4knAtF8fzHz1bULu1yMXfo+S%O(*y*?g7MJpnngoJ@UGM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vzp0L2lj1l(pe2S4m;z$~9{?1>2N1X;nB#UiH&6(R4;Hs(HAG z&d>w`)1G2;|gxsGUpXm=)YGwb2qhcSXeVgQTNUFAlKvKbw1j6nS)mi5%wgzAMj ze8mr~iNew$wFw341Dait6dmuvVL5XOSPqX(sFOc^1XesXCt5wyABpy;H0i9z$0oe! z9d8_1};#WHYFmGHAER;V4}^)zAF+Jv#31N@VUV zUk{ua<`@{vk3Q|gDp+BO|Fa;vjXH4EaBJ}%EU4I@63$82n$877?xkPD3WIKJrxeX&2*gFKlCd-2{csMyzoik|H4Px~#jXC~~$ z{(zvDa63_cp(p5VkkcNV;Ke?Ip#9ulw6VSZdB~|xguS`nz#n+TzMzON>_z<_;P$I{ z9I-DUsMwbzd$O_HKMIW6MEJ+Uo{=~e`>z}=J3~p>Be<;gUT!C7hpoYF?%5MI`vJc1 zA*j%&Sd;`W=q_N^_+sBgQ0q4ymF%Cj*^B2{L4(uDY9fia0(k)$YkaW}BdFNl7W(%2 zcYxcQ{qNA3trHVU`sov!rt76XatBP^bBr-7x-5Y(AX9BV!uNCJ0SFaN{Qwl zC1EG}@gIOu{e`{QpPIv8qzYtYNy1)GI;U^7X92FNkqNH`a@z-cHNNw eS$?sRN!kXSh%0nyx>vG);!;E7Oq+p?W&aIx>;xJB literal 0 HcmV?d00001 diff --git a/test/54.fa b/test/54.fa new file mode 100644 index 0000000..846537a --- /dev/null +++ b/test/54.fa @@ -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 diff --git a/test/54.fa.gz b/test/54.fa.gz new file mode 100644 index 0000000000000000000000000000000000000000..f93b98d92dc21a6b4bf39bf52d3c458f1da1272c GIT binary patch literal 113 zcmb2|=3oE==FQxGx+Wn7p1OW|r*t$3UtvjkTk-^st_J1l zvKJJTO_~k1G>1wCpSBWSw8nVpw9+(}$n?IeRth|YERN|MDyJF6Tr3X=bu)WxIdP$3 PfiHvW#j{&1m>3uUU#};; literal 0 HcmV?d00001 diff --git a/test/54.fq b/test/54.fq new file mode 100644 index 0000000..d85bad9 --- /dev/null +++ b/test/54.fq @@ -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 diff --git a/test/54.fq.gz b/test/54.fq.gz new file mode 100644 index 0000000000000000000000000000000000000000..16b9307c338b19d1daf474f7b3a0da01218d82f8 GIT binary patch literal 128 zcmb2|=3oE==3)*%U6YUkPhCH~Q#u+a&zyf;RL)aa!dKY-SRmbiudt-NEqMY*SA+6& zv+2T-4W}7jFe#geC*0`1Td^VTF=P2&PS$nivIW;?2R^7OUbBw%nS?wOmr_G literal 0 HcmV?d00001