From c742d6b58d9c3053e8ab3b025d8effc079ba3e5c Mon Sep 17 00:00:00 2001 From: ag Date: Fri, 20 Sep 2024 23:29:56 +0300 Subject: [PATCH] testing debug --- 2Q_cache.h | 65 +++++++++++++++++++++++++++++++++++++++++++------- cache_test.cpp | 9 +++++-- makefile | 26 ++++++++++---------- 3 files changed, 77 insertions(+), 23 deletions(-) diff --git a/2Q_cache.h b/2Q_cache.h index 173ca02..b34eab3 100644 --- a/2Q_cache.h +++ b/2Q_cache.h @@ -21,31 +21,61 @@ public: TwoCache(size_t q1sz, size_t q2sz): cpct_q1(q1sz), cpct_q2(q2sz) {} //ctor void put_page(int id) { + std::cout << "id: " << id << std::endl; + //std::cout <<__LINE__ << " " << __FILE__<< std::endl; + if (umap1.find(id) != umap1.end()) { //page is found, nothing to do (fast case) - return; + std::cout << "id ="<first) << ", Val: " << *(it->second) << " "; + } + + std::cout << std::endl; + + std::cout << "Umap2:\n"; + + for (auto it = umap2.begin(); it != umap2.end(); ++it) { + std::cout << "Key: " << it->first << ", Val: " << *(it->second) << " "; + } + + std::cout << std::endl< +const char* default_test_file = "tests.txt"; + int cache_test(std::string file_name) { std::ifstream file(file_name); @@ -47,7 +49,10 @@ int cache_test(std::string file_name) { } int main(int argc, char* argv[]) { - cache_test(argv[1]); - + if(argc == 0) { + cache_test(default_test_file); + } else { + cache_test(argv[1]); + } } diff --git a/makefile b/makefile index cc80797..18b2492 100644 --- a/makefile +++ b/makefile @@ -1,31 +1,33 @@ - TARGET = Q2 - CXX = g++ - CXXFLAGS = -Wall -Wextra -std=c++11 - SRCS = main.cpp TEST = cache_test.cpp - OBJS = $(SRCS:.cpp=.o) +ifeq ($(OS),Windows_NT) + RM = del + RUN = $(TARGET).exe +else + RM = rm -f + RUN = ./$(TARGET) +endif + all: $(TARGET) $(TARGET): $(OBJS) - $(CXX) -o $@ $^ + $(CXX) -o $@ $^ %.o: %.cpp - $(CXX) $(CXXFLAGS) -c $< -o $@ + $(CXX) $(CXXFLAGS) -c $< -o $@ test: - $(CXX) $(CXXFLAGS) $(TEST) -o cache_test - + $(CXX) $(CXXFLAGS) $(TEST) -o cache_test clean: - rm -f $(OBJS) $(TARGET) $(TEST) + $(RM) $(OBJS) $(TARGET) cache_test run: $(TARGET) - ./$(TARGET) + $(RUN) -.PHONY: all clean run \ No newline at end of file +.PHONY: all clean run test \ No newline at end of file