Showing posts with label Testing. Show all posts
Showing posts with label Testing. Show all posts

Monday, May 30, 2011

The Fairy's Sandbox

Sandboxes are isolated computational environments used for testing or security. For example, a testing sandbox may be a clean installation of a particular operating system and configuration, allowing you to control for the testing environment. Using a sandbox allows you to run code in an environment different from your development environment. Further, a sandbox protects the rest of the computer from potentially harmful effects of the program.


Ferr had barely slept all week. She was too excited. She had been waiting for this day for years. Today was the day that Ferr would finally learn to use her magical powers.


As the youngest fairy in a very large family, Ferr had always been jealous of her older siblings as they flew about and cast various spells. She longed for the day when she too could turn unsuspecting travelers' shoe-laces into worms. That was one of the best parts of being a fairy. Of course, like all young fairies, Ferr had never been permitted to venture outside of the safety of the magically protected kingdom. But, she had heard stories, and they sounded wonderfully fun.


Ferr arrived early to her first lesson. The first hour of the lesson was classroom instruction that reminded Ferr of her "History of the Fairy Kingdom" class. It was horribly dull. The instructor lectured in front of the class in a monotone voice about the origins of fairy magic and the importance of safety. Ferr had heard all of this before. She wanted to get onto the actual magic.


After the introductory lecture was done, Ferr's mentor took her to a practice room buried in the back of the school building. The room was nothing like Ferr had expected. It was a large, but simple, concrete room. It was furnished with a simple wooden table, two plain wooden chairs, a bright plastic beach ball, and a small potted flower.


"What is this place?" asked Ferr. She looked around nervously.


"It is a sandbox." responded her instructor as though that fact should be completely obvious.


"A sandbox?" asked Ferr. She had never heard of this before.


"Yes. You didn't think that we would let you try your magic in the middle of the kingdom, did you?"


"No… but… This does not look magical at all."


Ferr's mentor laughed. "Of course it is not. It is an ordinary room. You supply the magic."


"But, it could at least look magical." protested Ferr.


"The room is simple. That is the important part. You'll see."


Ferr was not sure what the last statement meant, but she let the topic go for now. She followed her mentor over to the center of the room and sat in one of the two chairs.


"First," her mentor began. "You are going to change the color of these flowers from blue to red. Do you know how to do that?"


Ferr nodded eagerly. She had seen her siblings practice changing the colors of flowers all the time. She cleared her mind and tried to concentrate. She gave her wand a quick flick at the flowers.


A large splotch of dark red appeared on the opposite wall. Ferr gasped. She had missed the flowers and stained the wall!


"Oh no!" she cried.


Her mentor did not appear upset in the least. "Try again, but keep your wrist tighter." she instructed.


"But… the wall?" asked Ferr. She had stained the wall. Was she going to be kicked out of school for this? Or banned from using magic? A scary parade of horrible scenarios marched through Ferr's mind.


Her instructor glanced back at the stain. With a quick flick of her own wand, the stain disappeared. "That is why we are in a sandbox." she added.


Over the next hour, Ferr saw the wisdom of the sandbox. Her incorrect spells repeatedly stained, scorched, and pummeled the simple room. To an outsider it would probably have looked as though Ferr had a vendetta against the room itself. But, each time, her mentor calmly restored the room to its previous state. And after 4 hours of practice, Ferr had even managed to turn the flowers a slight purplish.


The rest of the month was the same. Simple spells turned out to be surprisingly hard. And, Ferr repeatedly destroyed the room until she mastered them.


One morning a new surprise awaited Ferr. There, on the table, was a small lizard with a terrible temper. It hissed at her and tried to bite her repeatedly.


"I thought bog lizards could not get through the kingdom's magical protections!" yelped Ferr as it lunged for her. The creature's breath left no doubt that this was indeed a bog lizard.


"They cannot." agreed her mentor. "But we can bring them in here. This room is isolated from the rest of the kingdom. So, we can bring in all the dangerous creatures that we would not want to have running around wildly. You do need to practice dealing with unpleasant creatures, you know."


During that day's class, Ferr reached a new level of room destruction. She even managed to shatter the table. But ultimately, she learned to charm the lizard so that it would not hurt her. Still, the creature's horrible breath made her eager to finish up early.


It took a full year before a junior fairy was allowed to use magic outside of the sandbox, and now Ferr understood why. Ultimately, Ferr gained mastery of her skills and the destruction stopped. She was allowed to start using the magic spells that she had mastered within the sandbox. However, the original glee was replaced by a wiser feeling of caution.


And, Ferr always made sure to test new ideas in a sandbox. She would hate to accidentally turn the wallpaper in her room into fly paper as her older sister had done.



-------------------------


If you are interested in learning more about the importance of testing, check out the story of why it is important to always unit test your magic spells:

http://computationaltales.blogspot.com/2011/05/importance-of-unit-testing-magical.html

Monday, May 16, 2011

The Importance of Unit Testing Magical Spells

Unit tests are small tests designed to exercise specific components of a program, such as individual functions. The goal is to test components in isolation, allowing for: more targeted and thorough testing, quicker detection of errors, and finer grained debugging. Further, ensuring the correctness of the low level building blocks helps to better ensure the correctness of the overall program. Unit tests can also easily detect low level errors that might be masked by other logic in the program.


Marcus did not become a master wizard by being lazy. Unfortunately, it seemed as though the apprentices these days did not appreciate the value of hard work. His newest apprentice, Shelly, was obsessed with moving onto complex spells.


"You have to master the fundamentals first." Marcus insisted.


"But, I already know the fundamentals." Shelly responded petulantly.


Marcus sighed. Kids these days were so difficult. In his day, an apprentice did not argue with his or her master. You listened and were respectful. Why was everyone suddenly so impatient? Marcus blamed the latest pop culture fad: marching bands. Sadly, there was only one way to reinforce the value of correct building blocks.


"Okay." Marcus responded. "Today we will do the spell of Transmogrified Mold, which transforms ordinary house mold into a candy. It is a complex spell that requires six potions and three hours. Are you able to handle that?"


"Yes!" agreed Shelly readily. She was visibly bouncing with excitement.


Marcus smiled as he handed her the directions. "Here you go then. There should be plenty of mold in the kitchen. I believe a certain apprentice has not cleaned there in weeks."


Ignoring the comment, Shelly ran off to the kitchen to begin the spell.


The key to the spell of Transmogrified Mold was correctly making each of the six potions. If any one of the potions is off by even a little, the product is a complete failure. Granted, the result will still look, taste, and smell like chocolate. However, it will cause three hours of intense nausea and powerful hiccups. Together, those turn out to be a most unpleasant combination.


While Shelly buzzed around the kitchen working, Marcus decided to take a nap. No need to remind Shelly to test each potion individually. By this point in her training, the value of testing should be ingrained. Of course, young apprentices always complained that testing their potions slowed them down too much. But, there was really only one way to learn the value of unit testing potions.


Three hours later, Marcus was woken by the sound of loud vomiting. "I believe she is done." he mumbled to himself as he made his way down to the kitchen.


There he found Shelly, with her head in a bucket.


"How did it go?" he asked.


"I don't know what went wrong." moaned Shelly between hiccups.


"Well, let me just see." offered Marcus. He wandered over to the counter and started testing the individual potions.


The first three were correct.


"Ah. Too much vinegar in the fourth potion. Common mistake. My guess is that you did not notice, because there is too much salt in the last potion. Yep. There it is. All very common."


"But, they all looked correct." Shelly protested between powerful hiccups. "And the end result seemed to work out."


"You will be fine in another two hours and fifty three minutes. Until then, I would recommend keeping a bucket close." Marcus advised.


He paused at the door on his way out. He did not look back as he spoke. "And in the future, I would encourage you to thoroughly test each individual component of a spell. You need to make sure the fundamentals are correct before building off of them. Otherwise, you can find unpleasant surprises."