Compare commits

...

4 commits

Author SHA1 Message Date
Imbus
8abebb692a ignore 2024-11-27 17:15:16 +01:00
Imbus
4bb3629a76 Some assertions in tabletest 2024-11-27 17:14:47 +01:00
Imbus
cc34c03648 Makefile lab3 2024-11-27 17:14:34 +01:00
Imbus
c5e034c3ac Bugfix (assignment used over comparison) 2024-11-27 17:14:10 +01:00
4 changed files with 58 additions and 2 deletions

1
.gitignore vendored
View file

@ -7,3 +7,4 @@ words.txt
compile_commands.json
lab2/edit
lab2/spell
lab3/tabletest

33
lab3/Makefile Normal file
View file

@ -0,0 +1,33 @@
CXX = g++
CXXFLAGS = -Wall -Wextra -Wpedantic -Wshadow -Wnon-virtual-dtor -Wold-style-cast -Wcast-align -Wunused -Woverloaded-virtual -Wconversion -Wsign-conversion -Wnull-dereference -Wdouble-promotion -Wformat=2 -std=c++17
#CXXFLAGS += -Werror
SRC = $(wildcard *.cc)
HDR = $(wildcard *.h)
OBJ = $(SRC:.cc=.o)
all: tabletest $(OBJ)
tabletest: $(OBJ)
@echo "Building & linking $@"
@$(CXX) $(CXXFLAGS) $^ -o $@
%.o:%.cc
@echo "Building $@"
@$(CXX) -c $(CXXFLAGS) $< -o $@
lint: clang-tidy cppcheck clang-format
clang-tidy:
clang-tidy $(SRC) -- $(CXXFLAGS)
cppcheck:
cppcheck --enable=all --language=c++ --std=c++17 --suppress=missingIncludeSystem -I/usr/include $(SRC) $(HDR)
clang-format:
clang-format -i $(SRC) $(HDR)
clean:
rm -f *.o spell edit
.PHONY: clean all lint clang-tidy cppcheck clang-format

View file

@ -56,8 +56,8 @@ User UserTable::find(int c) const
while (low < high && ! found) {
mid = (low + high) / 2;
//
int midnbr = users[mid].getCardNbr();
if (midnbr = c) {
const int midnbr = users[mid].getCardNbr();
if (c == midnbr) {
found = true;
} else if (users[mid].getCardNbr() < c) {
low = mid + 1;

22
lab3/UserTableTest.cc Normal file
View file

@ -0,0 +1,22 @@
#include "UserTable.h"
#include "User.h"
#include <cassert>
int main() {
// Two identical users
User u1 = User(1234, "Name Nameson");
User u2 = User(1234, "Name Nameson");
assert(u1.getName() == u2.getName());
assert(u1.getCardNbr() == u2.getCardNbr());
// Two different users
User u3 = User(1200, "Name Surname");
User u4 = User(1201, "Name Nameson");
assert(u3.getName() != u4.getName());
assert(u3.getCardNbr() != u4.getCardNbr());
UserTable ut1 = UserTable("users.txt");
}