代写辅导接单-Phase 6: Unit Testing (Real-World Practice)

欢迎使用51辅导,51作业君孵化低价透明的学长辅导平台,服务保持优质,平均费用压低50%以上! 51fudao.top
Phase 6: Unit Testing (Real-World Practice)
In professional software development, programs are not trusted until they have
automated tests. As the final step of this assignment, you will add a unit
testing component after finishing your implementation and report.
Objectives
Validate the correctness of your search functions in isolation.
Exercise edge cases without running the full CLI program.
Gain real-world practice with automated testing.
What to Test
Write unit tests only for your core logic (do not call main() from main.cpp).
At a minimum, test:
count matches linear
count matches binary sorted
count matches binary recursive
(Optional) comparator functions for Book (operator==, operator<)
Starter File: tests.cpp
Below is a minimal unit test driver using assert. It is assuming that you created
enums form language and type but that is not necessarily required. You must
add at least 5 of your own tests (e.g., empty input, duplicates, type/language
mismatches).
#include <cassert>
#include <iostream>
#include <vector>
#include "book.h"
#include "search.h"
void test_linear_hit() {
std::vector<Book> newbooks = { {123, Lang::english, Type::New} };
std::vector<Book> requests = { {123, Lang::english, Type::New} };
assert(count_matches_linear(newbooks, requests) == 1);
}
void test_linear_miss() {
std::vector<Book> newbooks = { {123, Lang::english, Type::New} };
1std::vector<Book> requests = { {124, Lang::english, Type::New} };
assert(count_matches_linear(newbooks, requests) == 0);
}
int main() {
test_linear_hit();
test_linear_miss();
std::cout << "All unit tests passed!" << std::endl;
return 0;
}
2
51作业君

Email:51zuoyejun

@gmail.com

添加客服微信: Fudaojun0228