summaryrefslogtreecommitdiff
path: root/2019/rust/day09/test_ops.sh
diff options
context:
space:
mode:
Diffstat (limited to '2019/rust/day09/test_ops.sh')
-rwxr-xr-x2019/rust/day09/test_ops.sh85
1 files changed, 85 insertions, 0 deletions
diff --git a/2019/rust/day09/test_ops.sh b/2019/rust/day09/test_ops.sh
new file mode 100755
index 0000000..4e78122
--- /dev/null
+++ b/2019/rust/day09/test_ops.sh
@@ -0,0 +1,85 @@
+#!/bin/sh -e
+
+E="../target/debug/day09"
+
+### https://adventofcode.com/2019/day/2
+
+# Opcode 1 adds together numbers read from two positions and stores the result
+# in a third position. The three integers immediately after the opcode tell you
+# these three positions - the first two indicate the positions from which you
+# should read the input values, and the third indicates the position at which
+# the output should be stored.
+
+# Opcode 2 works exactly like opcode 1, except it multiplies the two inputs
+# instead of adding them. Again, the three integers after the opcode indicate
+# where the inputs and outputs are, not their values.
+
+### https://adventofcode.com/2019/day/5
+
+# Opcode 3 takes a single integer as input and saves it to the position given
+# by its only parameter. For example, the instruction 3,50 would take an input
+# value and store it at address 50.
+
+# Opcode 4 outputs the value of its only parameter. For example, the
+# instruction 4,50 would output the value at address 50.
+
+# Each parameter of an instruction is handled based on its parameter mode.
+# Right now, your ship computer already understands parameter mode 0, position
+# mode, which causes the parameter to be interpreted as a position - if the
+# parameter is 50, its value is the value stored at address 50 in memory. Until
+# now, all parameters have been in position mode.
+
+# Now, your ship computer will also need to handle parameters in mode 1,
+# immediate mode. In immediate mode, a parameter is interpreted as a value - if
+# the parameter is 50, its value is simply 50.
+
+# Opcode 5 is jump-if-true: if the first parameter is non-zero, it sets the
+# instruction pointer to the value from the second parameter. Otherwise, it
+# does nothing.
+
+# Opcode 6 is jump-if-false: if the first parameter is zero, it sets the
+# instruction pointer to the value from the second parameter. Otherwise, it
+# does nothing.
+
+# Opcode 7 is less than: if the first parameter is less than the second
+# parameter, it stores 1 in the position given by the third parameter.
+# Otherwise, it stores 0.
+
+# Opcode 8 is equals: if the first parameter is equal to the second parameter,
+# it stores 1 in the position given by the third parameter. Otherwise, it
+# stores 0.
+
+### https://adventofcode.com/2019/day/9
+
+# Opcode 9 adjusts the relative base by the value of its only parameter. The
+# relative base increases (or decreases, if the value is negative) by the value
+# of the parameter.
+
+PROGRAMS=${@:-programs/test-*.iac}
+for PROGRAM in ${PROGRAMS}
+do
+ echo "Starting ${PROGRAM}"
+ if [ -e ${PROGRAM%.iac}.in ]; then
+ INPUT=`cat ${PROGRAM%.iac}.in`
+ else
+ INPUT="0"
+ fi
+
+ if [ -e ${PROGRAM%.iac}.out ]; then
+ EXPECTED="`cat ${PROGRAM%.iac}.out`"
+ else
+ EXPECTED=""
+ fi
+
+ OUTPUT=`echo "${INPUT}" | RUST_BACKTRACE=1 \
+ "${E}" --program "${PROGRAM}" --mode stdio '0' | tee /dev/stderr`
+ echo "${PROGRAM} finished"
+ if [ "${EXPECTED}" = "${OUTPUT}" ]; then
+ echo "Expected output recieved: ${OUTPUT}"
+ else
+ echo "Incorrect output!"
+ echo "Expected |${EXPECTED}| != Actual |${OUTPUT}|"
+ exit 1
+ fi
+ echo ""
+done