From 679fa4f220c40e552d4ba4e67669680f10c21a6d Mon Sep 17 00:00:00 2001 From: Richard Qin Date: Thu, 24 Sep 2026 19:22:15 +0800 Subject: lab01 --- lab01/Makefile | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 lab01/Makefile (limited to 'lab01/Makefile') diff --git a/lab01/Makefile b/lab01/Makefile new file mode 100644 index 0000000..527d7ed --- /dev/null +++ b/lab01/Makefile @@ -0,0 +1,51 @@ +CXX := g++ +CXXFLAGS := -std=c++11 -Wall -Wextra -Wpedantic -O2 + +TARGET := triplet +SOURCE := main.cc +HEADER := Triplet.hh + +.PHONY: build test + +build: $(TARGET) + +$(TARGET): $(SOURCE) $(HEADER) + $(CXX) $(CXXFLAGS) $(SOURCE) -o $(TARGET) + +test: build + @passed=0; \ + failed=0; \ + total=0; \ + for input in *.in; do \ + if [ ! -f "$$input" ]; then \ + continue; \ + fi; \ + total=$$((total + 1)); \ + base=$${input%.in}; \ + expected="$$base.out"; \ + actual="$$base.actual"; \ + if [ ! -f "$$expected" ]; then \ + echo "[FAIL] $$input: missing $$expected"; \ + failed=$$((failed + 1)); \ + continue; \ + fi; \ + if ./$(TARGET) < "$$input" > "$$actual"; then \ + if diff -u "$$expected" "$$actual" > /dev/null; then \ + echo "[PASS] $$base"; \ + passed=$$((passed + 1)); \ + else \ + echo "[FAIL] $$base"; \ + diff -u "$$expected" "$$actual" || true; \ + failed=$$((failed + 1)); \ + fi; \ + else \ + echo "[FAIL] $$base: program exited with an error"; \ + failed=$$((failed + 1)); \ + fi; \ + rm -f "$$actual"; \ + done; \ + echo; \ + echo "Passed: $$passed / $$total"; \ + if [ "$$failed" -ne 0 ]; then \ + exit 1; \ + fi -- cgit v1.2.3