Browse Source

Add test

master
Daniel 6 months ago
parent
commit
88f3230f90
4 changed files with 14 additions and 10 deletions
  1. +1
    -1
      LICENSE
  2. +4
    -0
      Makefile
  3. +3
    -4
      biblec.c
  4. +6
    -5
      test.c

+ 1
- 1
LICENSE View File

@@ -1,4 +1,4 @@
MIT License Copyright (c) <year> <copyright holders>
MIT License Copyright (c) 2020- Daniel C

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal


+ 4
- 0
Makefile View File

@@ -0,0 +1,4 @@
CC := tcc
test:
@$(CC) *.c -o biblec
@valgrind ./biblec

+ 3
- 4
biblec.c View File

@@ -1,5 +1,6 @@
#include <stdio.h>
#include <string.h>

#include "main.h"

// Split chars and ints from string
@@ -108,7 +109,7 @@ int biblec_next(struct Biblec_reader *reader) {
return 0;
}

strtok(reader->result, "\n"); // Strip '\n' from file
strtok(reader->result, "\n"); // Strip '\n'
reader->linesRead++;
return 1;
@@ -119,13 +120,11 @@ int biblec_new(struct Biblec_reader *reader, struct Biblec_translation *translat
char *book, int chapter, int verse, int to) {
int c;

// Check book ID
int bookID = getBookID(translation, book);
if (bookID == BOOK_NOT_FOUND) {
return BOOK_NOT_FOUND;
}

// Check if requested chapter is larger than book length
if (translation->book[bookID].length < chapter) {
return CHAPTER_TOO_BIG;
}
@@ -137,7 +136,7 @@ char *book, int chapter, int verse, int to) {
}

// When 0 is passed for "to", grab the entire chapter.
// Else, "to" refers to how many verse to
// Else, "to" refers to how many verses to
// count in the struct.
if (to == 0) {
to = translation->book[bookID].chapters[c] - 1;


+ 6
- 5
test.c View File

@@ -7,7 +7,7 @@
// Runtime struct
struct Biblec_translation translation;

int test(struct Biblec_reader *reader, char name[], int chapter, int from, int to) {
void test(struct Biblec_reader *reader, char name[], int chapter, int from, int to) {
int tryReader = biblec_new(
reader,
&translation,
@@ -19,7 +19,8 @@ int test(struct Biblec_reader *reader, char name[], int chapter, int from, int t

if (tryReader) {
puts("Verse error");
return 1;
biblec_close(reader);
exit(1);
}

while (biblec_next(reader)) {
@@ -41,7 +42,7 @@ int main() {
}

struct Biblec_reader reader;
for (int i = 0; i < 100000; i++) {
test(&reader, "Gen", 1, 1, 1);
}
test(&reader, "Gen", -1000, -1000, 16);
test(&reader, "Gen", 2147483647, 2147483647, 2147483647);
}

Loading…
Cancel
Save