Archive for the ‘Study’ Category

Common PHP Test Utilities

Saturday, January 16th, 2010

Writing tests can be repetitive, even if you try to adhere to DRY principals. I’m using the PHP Simple Test library to run my tests, since it’s been written, it’s good and there’s no reason for me to write my own. However, I’m not using a heavy framework with an ORM, rather a light framework (Swiftlet) with my own DAO.

Here are my test utilities so far, they’ve been useful for general models and have helped increase test coverage while reducing code:

<?php
/**
 * TestUtils 
 * Utilities not included in test library that are commonly used in tests
 * 
 * copyright 2010 logon2 http://www.logon2.com.au
 * license http://opensource.org/licenses/gpl-3.0.html GNU Public License
 */
 
class TestUtils {
 
	function confirmSaveAndRestore($saved, $restored) {
		/*
		* Confirms the values saved to a database are
		* retreived accurately. 
		* saved can either be an array of key/value pairs OR
		* an array of an array of key/value pairs.
		*
		* The format of $restored must match that of $saved
		*/
 
		//determine if we're testing multiple values
		if (is_array($saved)) { 
			foreach ($saved as $key => $value) {
				if (!$key) {
					$array = true;
				} else {
					$array = false;
					break;
				}
			}
		} else {
			//the input MUST be an array or an array of an array
			throw new Exception("Input must be at least a 1D array");
		}
 
		if ($array = false) {
			$responses = array($saved);
		} else {
			$responses = $saved;
		}
 
		foreach ($responses as $response) {
			if (is_array($saved) && is_array($restored)) {
 
				foreach ($saved as $key => $value) {
					if ($restored[$key] != $value) {
						return false;
					}
				}
				return true;
			} else {
				throw new Exception("Inconsistent input");
			}
		}
	}
 
	function overwriteAttributes($attributes, $updates) {
		/*
		* Will overwrite attributes from $attributes with all attributes 
		* found in $updates, but leave all others
		*
		* This can be useful for testing edits
		*/
 
		if (is_array($updates)) {
			foreach ($updates as $key => $value) {
				$attributes[$key] = $value;
			}
		}
		return $attributes;
	}
 
	function generateBadValSet($badVals, $goodVals) {
		/*
		* Will generate a complete set of values, 
		* each with exactly one bad value from $badVals
		*
		* I was thinking if I should make it generate
		* all possibilities (n^m) rather than just
		* a set of values each with exactly one bad value.
		*/
		$badValSet = array();
 
		foreach($badVals as $attribute => $badVal) {
			if (!is_array($badVal)) {
				//more than one bad value for attribute
				$badVal = array($badVal);
			}
 
			foreach ($badVal as $thisBadVal) {
				$theseBadVals = $goodVals;
				$theseBadVals[$attribute] = $thisBadVal;
 
				$badValSet[] = $theseBadVals;
			}
		}
 
		return $badValSet;
 
	}
 
}
 
?>

Ironically, I have no test for these Test Utilities so beware ;)

5 Things About The iPhone That Has Evolutionised Mobile Phones

Wednesday, September 9th, 2009

Counter Notions has written a list of 25 things that Apple’s iPhone has done to revolutionise the mobile landscape. Most of these are either US-specific, even US-carrier-specific, even AT&T specific or just not true. I replied with a pretty hefty comment so rather than leave it there where it will likely be ignored and dismissed by members of a certain cult, I thought I’d put a copy here. Besides, I haven’t posted in about 2.5*10^-7 ages.

iPhone? Son, I am disappoint.

25 5 Things iPhone Has Done To R Evolutionise Mobile Phones

Before iPhone was launched: (more…)

Using RMIT Online In 2009 (not in 2001)

Tuesday, July 21st, 2009

If you’re an RMIT university student, you probably hate Blackboard. If the Web Industry took a huge dump in 2001 , Blackboard is what it would look like. Blackboard’s not RMIT’s only annoying web service. Their 1995-style webmail is hilarious and Weblearn makes baby Jesus cry.

To give a bit of credit, myRMIT has made it easier to access RMIT’s web services, but it still has some way to go. For instance, somebody’s decided that RMIT students LOVE new windows and always have 215 Netscape windows open when they’re surfin’ the world wide web looking at the dancing baby. They believed this so much that they have made it difficult to avoid opening a new window by using javascript ONLY to direct links. Gross.

Well not me. I use Firefox because I don’t hate myself and use these fancy things called tabs to manage multiple pages at a time. I also like to use Bookmarks for quick access to frequently viewed web pages. (Yeah, I know I’m so futuristic)

As a generous internet citizen, I’d like to offer these direct links for RMIT students:

RMIT Online Direct URLs

Blackboard (Whackboard):

https://learninghub.rmit.edu.au/lhub-portal/portal/track/sso/tool.do;?tool_shell_id=YOURCOURSECODE&resource=BLACKBOARD

(Where YOURCOURSECODE is the course code seen on blackboard, like in image below …)
whackboard

Save about 2 – 3 Clicks. myRMIT > Learning Hub > Blackboard

RMIT Forum:

http://forums.rmit.edu.au/forums/forums/list.page?caslogin=true

Saving you about 3 clicks here. myRMIT > Lounge >Forum Recent.

RMIT Classifieds:

http://classifieds.rmit.edu.au/classifieds/?caslogin=true

This aught to save you about 3 clicks :) myRMIT > Lounge > Classifieds Recent

RMIT Webmail:

http://pwd.student.rmit.edu.au/
(Don’t bother using the webmail, you should just forward it to your own email address. If you do this you’re less likely to self-mutilate)

RMIT Learning Hub:

http://www.rmit.edu.au/learninghub

Want a quick link to something else? Well figure it out yourself! Alternatively, just ask in comments. If I’m not busy moderating my meditating, soy latte drinking, vegan yoga enthusiast web forum then I’ll see what I can do.

Perfect Fit Party Supplies Pty. Ltd.

Monday, July 13th, 2009

Perfect Fit Party Supplies Pty. Ltd.

Become a fan of Perfect Fit on Facebook or go to Perfect Fit’s MySpace Page

Make “Unexpected end of line seen” Solution

Wednesday, March 25th, 2009

For Programming Concepts course our assignment requires us to use Make to compile and archive our programs for submission. Unfortunately I couldn’t get any of my makefiles to work, whenever I ran “Make” I’d get the rather unspecific error:

Unexpected end of line seen

The problem was occurring in Unix and Ubuntu Linux, so it wasn’t platform specific.

Solution

Use tabs (\t) instead of spaces. I have all of my text editors configured to use four spaces instead of \t because my university programming assignments always seem to state this requirement.

Replacing “    ” with “\t” did the trick for me.

RMIT’s Server Struggles

Monday, March 2nd, 2009

It’s the first day here at RMIT and it appears that the “blackboard” server is dying… hard. I’m trying to download the content for all of my courses and i’m getting timeouts about 80% of the time.

Praise Firefox and DownThemAll, for it retries automatically until (undefined).RMIT Tomcat "Server" Failing to Serve

But what do we expect? The platform is Java running through Apache / Tomcat. I hate Tomcat.

Note: It could actually be my computer / network connection.

EEET 2249 – Tutorial 5 – Problems

Saturday, September 13th, 2008

Circuits with voltage and current sources *Unsolved*

(more…)

EEET2249 Circuit Theory Week 4

Saturday, September 13th, 2008

(more…)

EEET 2249 Tutorial 3

Saturday, September 13th, 2008

(more…)

EEET 2249 Tutorial 2

Saturday, September 13th, 2008

(more…)