كيفية استخدام ملفات .in و .out للاختبار في بيئة يونكس؟
سؤال
لدي برنامج C++ ومجموعة من ملفات .in و .out للاختبار المسبق.كنت أتساءل عن كيفية تنفيذ برنامج c++ الخاص بي وإدخاله فيه.
المحلول
أفترض أن لديك قائمة بالملفات مثل test0.in
و المقابلة test1.out
.ربما تريد ملف Makefile مثل هذا:
#Put rules/variables to actually make the program
SRC = test.cpp
TARGET = program
INPUTS = $(shell ls *.in)
OUTPUTS = $(patsubst %.in, %.out, $(INPUTS))
TESTS = $(patsubst %.in, %.test, $(INPUTS))
#This build rule is just for showcase. You will probably need your own, more sophisticated build rules
$(TARGET): $(SRC)
g++ $^ -o $@ -std=c++11
.PHONY: test
test: $(TESTS)
%.test : %.in %.out $(TARGET)
@./$(TARGET) < $*.in > $@;
@if cmp -s $@ $*.out; then \
echo "PASS: $*"; \
else \
echo "FAIL: $*"; \
fi
@rm $@
ثم اكتب فقط make test -j
للاختبار متعدد الخيوط.
لا تنتمي إلى StackOverflow