From 69124344c75e7778bd5b85a70c4dcd1ded7cb521 Mon Sep 17 00:00:00 2001 From: Octavio Alvarez Date: Fri, 1 Nov 2013 15:34:12 -0700 Subject: [PATCH] New test/remainder, use modulo operation --- GNUmakefile | 2 +- solutions-python/remainder.py | 5 +++++ test/remainder | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 solutions-python/remainder.py create mode 100755 test/remainder diff --git a/GNUmakefile b/GNUmakefile index 50891c2..0890394 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -1,4 +1,4 @@ -CHALLENGES := execute hello twoplustwo firstarg firstarg-int square +CHALLENGES := execute hello twoplustwo firstarg firstarg-int square remainder COMPLETION := $(CHALLENGES:%=done/%.done) diff --git a/solutions-python/remainder.py b/solutions-python/remainder.py new file mode 100644 index 0000000..c31ad05 --- /dev/null +++ b/solutions-python/remainder.py @@ -0,0 +1,5 @@ +#!/usr/bin/env python + +import sys + +print int(sys.argv[1]) % 10 diff --git a/test/remainder b/test/remainder new file mode 100755 index 0000000..adb7730 --- /dev/null +++ b/test/remainder @@ -0,0 +1,35 @@ +#!/bin/bash + +ME=$(basename "$0") + +if [ "$1" == "--help" ]; then + echo "Create a program that extracts and prints the last digit of a" + echo "given number. The number will be provided as the first argument" + echo "of the program." + echo + echo "For example, if the program is called like:" + echo " $ME 256" + echo "the program should print:" + echo " 6" + exit 0 +fi + +RESULT=$(run/"$ME" 289) + +if [ "$RESULT" != "9" ]; then + exit 1 +fi + +RESULT=$(run/"$ME" 1512) + +if [ "$RESULT" != "2" ]; then + exit 1 +fi + +RESULT=$(run/"$ME" 3) + +if [ "$RESULT" != "3" ]; then + exit 1 +fi + +touch done/"$ME".done