+/EE312

software design

git clone https://git.julia.blue/+/EE312

Joseph RyanAdd Project 1 and start Project 2f830e85

master
2.9 KiB86 linesraw
1
2#define _CRT_SECURE_NO_WARNINGS 1 // this #define is for VS2012, which doesn't like the standard C library
3
4#include <stdio.h> // declaraations of standard input/output functions
5#include <stdint.h> // declarations of standard integer types (e.g., int32_t)
6#include <stdlib.h> // declarations of general functions in the standard library (e.g., abort, exit)
7
8
9#define ONE_MB (1 << 20)
10#define BUFFER_SIZE ONE_MB
11
12char dictionary[BUFFER_SIZE]; // a large buffer to hold a dictionary (1MB)
13char article[BUFFER_SIZE]; // a large buffer to hold an article (1MB)
14
15void spellCheck(char[], char[]); // this is the function you write (put your function in Project1.cpp
16
17/*
18 * Read a .txt file into one of the two buffers
19 * this function does NOT confirm that the file is correctly formatted
20 */
21void readFile(const char file_name[], char buffer[]) {
22	FILE* file = fopen(file_name, "r");
23	if (file == 0) {
24		printf("unable to open file \"%s\"\n", file_name);
25		abort();
26	}
27
28	/* clear (set to zeros) the buffer */
29	for (uint32_t k = 0; k < BUFFER_SIZE; k += 1) {
30		buffer[k] = 0;
31	}
32
33	/* read the file (this is a binary read, which is OK) */
34	uint32_t bytes_read = fread(buffer, 1, BUFFER_SIZE, file);
35	buffer[bytes_read] = 0;
36}
37
38void fruityTest(void) {
39	printf("\n\n******* Starting Base Test #1 (fruity) *******\n");
40	char dictionary[] = "apple\nbanana\norange\npear\n";
41	char article[] = "I ate an apple and a pear\n";
42	spellCheck(article, dictionary); // should print: ate, an, and 
43	printf("****DONE****\n");
44}
45
46void dogTest(void) {
47	printf("\n\n******* Starting Base Test #2 (dogs) *******\n");
48	char dictionary[] = "Beagle\nBulldog\nCollie\nPoodle\nretriever\n";
49	char article[] = "bulldog dalmation beagle Retriever poodles";
50	spellCheck(article, dictionary); // should print: dalmation poodles
51	printf("****DONE****\n");
52}
53
54void punctuationTests(void) {
55	printf("\n\n******* Starting Base Test #3 (punctuation) *******\n");
56	char dictionary[] = "but\ncan\ncan't\ndo\ndon't\nthink\n"; // the dictionary can contain punctuation
57	char article[] = "I think I can, but I can't. I think I do, but I don't";
58	spellCheck(article, dictionary); // should print: don
59	printf("****DONE****\n");
60}
61
62void generalTest1(void) {
63	printf("\n\n******* Starting General Test #1 *******\n");
64	readFile("greek-finances.txt", article);
65	readFile("american-english.txt", dictionary);
66	spellCheck(article, dictionary);
67	printf("****DONE****\n");
68}
69
70void generalTest2(void) {
71	printf("\n\n******* Starting General Test #2 *******\n");
72	readFile("bobsledding.txt", article);
73	readFile("american-english.txt", dictionary);
74	spellCheck(article, dictionary);
75	printf("****DONE****\n");
76}
77
78/* you should also make your own tests! */
79int main(void) {
80    /* for starters, uncomment the following tests, one at a time */
81    fruityTest();
82    dogTest();
83    punctuationTests();
84    generalTest1();
85    generalTest2();
86}