Commit 899229bf authored by Christophe Rhodes's avatar Christophe Rhodes

updates to 00 01

parents
Pipeline #323 failed with stages
01/cpp/SetupTest
02/cpp/HelloTest
03/cpp/DynamicArrayCounter
03/cpp/DynamicArrayTest
04/cpp/SLListTest
05/cpp/SLListTest
06/cpp/SLListTest
06/cpp/StackQueue
07/cpp/ListVisualiserDriver
08/cpp/HashTableTest
09/cpp/StringMatchCount
09/cpp/StringMatchTest
09/cpp/NaiveStringMatchTest
09/cpp/RKStringMatchTest
09/cpp/KMPStringMatchTest
12/cpp/BinarySearchTest
13/cpp/HeapTest
14/cpp/GraphTest
**/cpp/*.o
**/java/*.class
**/test.xml
README.pdf
README.tex
2016-17
\ No newline at end of file
#include "OpCounter.hpp"
OpCounter::OpCounter() {
}
void OpCounter::add(int n) {
counter += n;
}
int OpCounter::report() {
return counter;
}
#ifndef OPCOUNTER_HPP
#define OPCOUNTER_HPP
class OpCounter {
private:
int counter = 0;
public:
OpCounter();
void add(int);
int report();
};
#endif /* OPCOUNTER_HPP */
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/CompilerOutputter.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
#include <cppunit/ui/text/TestRunner.h>
int main(int argc, char *argv[]) {
if (argc > 2) {
std::cerr << "Usage: " << argv[0] << " [suitename]" << std::endl;
return 1;
}
CppUnit::Test *test;
CppUnit::TextUi::TestRunner runner;
if (argc == 2)
test = CppUnit::TestFactoryRegistry::getRegistry(argv[1]).makeTest();
else
test = CppUnit::TestFactoryRegistry::getRegistry().makeTest();
runner.addTest(test);
runner.setOutputter(new CppUnit::CompilerOutputter(&runner.result(), std::cerr));
bool wasSuccessful = runner.run();
return wasSuccessful ? 0 : 1;
}
class OpCounter {
private int count = 0;
public void add(int n) {
count += n;
}
public int report() {
return count;
}
}
#+TITLE: Algorithms & Data Structures: Lab 01
#+SUBTITLE: week of 1st October 2018
#+include: ../labsheet.org
* Setup
** Installing and configuring software
In this series of labs, you will be asked to write programmes with
specified behaviours. You will be provided with test cases which
probe whether you have correctly implemented your programmes.
*** Programming language
In order to compile your programmes, you will need to install a
compiler and runtime. Which compiler will depend on your choice
of programming language for Principles and Applications of
Programming: for Games Programming students, this will be C++; for
most Computer Science students, this will be Java. You must tell
me about your choice by visiting [[https://learn.gold.ac.uk/course/view.php?id=11491][the learn.gold page]] for this
module and [[https://learn.gold.ac.uk/mod/choicegroup/view.php?id=601048][selecting your programming language]].
*** Development environment
You will need to install a development environment. How you do
this depends on your operating system and programming language.
Follow [[https://learn.gold.ac.uk/mod/url/view.php?id=601050][instructions on learn.gold]] to identify what you need to do,
and the respective installation procedures for the software you
need to get started.
** Getting the lab distribution
You will also need to get the lab code, which is distributed from a
[[http://gitlab.doc.gold.ac.uk/crhodes/is52038b-labs][git repository]] hosted on the [[http://gitlab.doc.gold.ac.uk][Department's gitlab instance]]. You
should be able to issue the following command from a terminal:
#+begin_example
git clone http://gitlab.doc.gold.ac.uk/crhodes/is52038b-labs.git
#+end_example
and the lab bundle code will be downloaded to the =is52038b-labs=
directory relative to your current directory.
** Testing your installation
Once you have performed all the previous steps, you should have a
directory containing the lab bundle. This directory will be under
version control – more on that in a couple of weeks – and you
should try to keep track of your changes to it.
For now, what you should do is test whether your installation and
configuration of software has worked. To do that, run the two
commands
#+begin_example
make test
cd is52038b-labs/01/java
#+end_example
if you are learning Java, and
#+begin_example
cd is52038b-labs/01/cpp
make test
#+end_example
if you are learning C++.
If your installation is working, you should get a reassuring
message. If it isn't, you are likely to get a hard-to-understand
error message; if you don't know how to go about fixing the
problem, please ask on the [[https://learn.gold.ac.uk/mod/forum/view.php?id=600474][discussion forum]].
include ../../cpp.mk
SetupTest: SetupTest.o ../../00/cpp/RunTests.o
test: SetupTest
@echo "Running test of CppUnit"
@./SetupTest
@echo "Tests passed: C++ setup apparently OK"
.PHONY: test
#include <cppunit/extensions/HelperMacros.h>
class SetupTest : public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(SetupTest);
CPPUNIT_TEST(testSetup);
CPPUNIT_TEST_SUITE_END();
public:
void setUp() { };
void tearDown() { };
void testSetup();
};
void SetupTest::testSetup() {
CPPUNIT_ASSERT_MESSAGE("CppUnit is not working", true);
}
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(SetupTest, "Setup");
CPPUNIT_REGISTRY_ADD_TO_DEFAULT("Setup");
include ../../java.mk
TESTCLASSFILES = SetupTest.class
CLASSFILES = $(TESTCLASSFILES)
all: $(CLASSFILES)
test: all
@echo "Running test of JUnit4"
@(((($(JAVA) $(CP) $(CLASSPATH) org.junit.runner.JUnitCore $(subst .class,,$(TESTCLASSFILES)); echo $$? >&3) | egrep -v \(org.junit\|sun.reflect\|java.lang.reflect\) >&4) 3>&1) | (read xs; exit $$xs)) 4>&1
@echo "Tests passed: Java setup apparently OK"
clean:
-rm *.class
.PHONY: test clean all
import org.junit.Test;
import static org.junit.Assert.assertTrue;
public class SetupTest {
@Test
public void testSetup() {
assertTrue("JUnit4 is not working", true);
}
}
#!/bin/sh
# I'm not proud of this
set -e
DESTDIR=${HOME}/Goldsmiths/is52038b-labs/
rsync -avh $(git ls-files . | grep -v /) ${DESTDIR}
for subdir in "$@"
do
rsync -avhR $(git ls-files "${subdir}") ${DESTDIR}
done
cd ${DESTDIR}
git add .
if [ $# -gt 0 ]
then
git commit -m "updates to $*"
else
git commit -m "updates to generic infrastructure"
fi
LDLIBS += -lcppunit -lstdc++
CXXFLAGS += -std=c++11
ifeq ($(OS),Windows_NT)
MYOS := Windows
else
MYOS := $(shell uname -s)
endif
ifeq ($(MYOS),Darwin)
CPPUNITDIR = /Users/Shared/CppUnit
CPPFLAGS += -I$(CPPUNITDIR)/include -I/usr/local/include
LDFLAGS += -L$(CPPUNITDIR)/lib -L/usr/local/lib
endif
CPPFLAGS += -I../../00/cpp
ifeq ($(OS),Windows_NT)
ifneq ($(wildcard /c/Program\ Files/Java/jdk1.8*),)
JDIR = $(wordlist 1,2,$(wildcard /c/Program\ Files/Java/jdk1.8*))
JAVAC = "$(JDIR)"/bin/javac
JAVA = "$(JDIR)"/bin/java
else
ifneq ($(wildcard /c/Program\ Files/Java/jdk-9*),)
JDIR = $(wordlist 1,2,$(wildcard /c/Program\ Files/Java/jdk-9*))
JAVAC = "$(JDIR)"/bin/javac
JAVA = "$(JDIR)"/bin/java
else
## remove the # symbols from the two lines below, and write in
## the path to javac and java on your system, such as
# JAVAC = /c/Program\ Files/Java/jdk-18.3/bin/javac
# JAVA = /c/Program\ Files/Java/jdk-18.3/bin/java
endif
endif
else
JAVAC = javac
JAVA = java
endif
CP = -cp
CLASSPATHS = . ../../00/java ../../00/java/junit-4.12.jar ../../00/java/hamcrest-core-1.3.jar
empty :=
space := $(empty) $(empty)
CLASSPATH = $(subst $(space),:,$(CLASSPATHS))
%.class: %.java
$(JAVAC) $(CP) $(CLASSPATH) $^
#+OPTIONS: toc:nil author:nil date:nil
#+LaTeX_HEADER: \usepackage{fontspec}
#+LaTeX_HEADER: \setmainfont[Mapping=tex-text]{Libertinus Serif}\setsansfont[Mapping=tex-text]{Libertinus Sans}
#+LaTeX_HEADER: \usepackage{unicode-math}
#+LaTeX_HEADER: \setmathfont{Libertinus Math}
#+LaTeX_HEADER: \usepackage[margin=1in]{geometry}
#+LaTeX_HEADER: \usepackage{algpseudocode}
#+LaTeX_HEADER: \algnewcommand\algorithmicbreak{\textbf{break}}
#+LaTeX_HEADER: \algnewcommand\Break{\algorithmicbreak{} }%
#+LaTeX_HEADER: \algnewcommand\algorithmiccontinue{\textbf{continue}}
#+LaTeX_HEADER: \algnewcommand\Continue{\algorithmiccontinue{} }%
#+LaTeX_HEADER: \MakeRobust{\Call}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment