Semantic Test Plan – KFrog Language

This post is an extract from one of my earlier project under Prof. Alfred Aho for the course – Programming Language & Translators, where I implemented a Test Suite for validating the KFrog Language interpreter.

Report: http://docs.google.com/viewer?url=http://gauravpandey.webs.com/KFrog_FinalProjectReport.pdf

Technical details: https://docs.google.com/View?id=d8gtx9j_164g2gz7k5x

Originally, the idea was to test the graphical output generated by the interpreter. Since, it was JVM dependent we assumed that Java would produce the correct graphical output as long as our interpreter correctly interpreted the given program. Thus, the focus shifted to testing the semantics (grammar) of the language. To accomplish this, we decided of having an intermediate language which would be the de facto representation for debug messages and expanded-gold statements. My general strategy to semantic testing was a 4-step approach as outlined below:

Step 1 involved delving into the gold standard representation format. I had to come up with a format which would enable a tester to perform testing in the simplest possible way.  To that end we decided that a Web based markup language related representation would be ideal. HTML was chosen as the representative language for our gold standard representation of Test Cases.

   1:  <pond xsize="" ysize="" color="">
   2:  <frog id="">
   3:  </center>
   4:  </startdraw>
   5:  <loop value="">
   6:  </action type="" value="">
   7:  </action type="" valuemin="" valuemax="">
   8:  </curve type="" radius="" degree="">
   9:  </curve type="" radiusmin="" radiusmax="" degreemin="" degreemax="">
  10:  </goto xvalue="" yvalue="">
  11:  </goto xvaluemin="" xvaluemax="" yvaluemin="" yvaluemax="">
  12:  </loop>
  13:  </stopdraw>
  14:  </frog>
  15:  </pond>

In Step 2, we fetch the debug messages generated by the Interpreter by passing the parameter –test-semantics. This enables us to generate a .debug file which is a true mapping of the graphics generated on the screen. The following is a typical set of debug statements for generating a square of side 100.

   1:  pondsize 300,300
   2:  pondcolor WHITE
   3:  1 new Frog {
   4:  1 center
   5:  1 frogcolor BLUE
   6:  1 speed 3
   7:  1 startdraw
   8:  1 forward 100
   9:  1 turnleft 90
  10:  1 forward 100
  11:  1 turnleft 90
  12:  1 forward 100
  13:  1 turnleft 90
  14:  1 forward 100
  15:  1 turnleft 90
  16:  1 stopdraw
  17:  1 }

In Step 3, we formulate the test cases which are capable of testing a specific subset of the language all at once. The following is a gold standard representation for generating a square of length 100

   1:  <pond xsize="400" ysize="400" color="white">
   2:  <frog id="1">
   3:  </center>
   4:  </startdraw>
   5:  <loop value="4">
   6:  </action type="forward" value="100">
   7:  </action type="turnleft" value="90">
   8:  </loop>
   9:  </stopdraw>
  10:  </frog>
  11:  </pond>

In step 4, we utilize the Tester program which fetches the content of .debug and .gold file and populates 2 data structures (Vectors). The data stored in the data structures is in an Intermediate Format. In turn, both data structures are compared for exactness and a final response is provided – ‘PASS’ or ‘FAIL’. The following diagram shows the entire process in detail:


 

Technical Certifications are like a TAX!

Just like many other Software Developers and Network Administrators, I was wondering whether Certifications in a particular technical domain will be advantageous in a way. Microsoft, Cisco, Oracle, Red-Hat and countless others have their own set of certifications to assess, evaluate & justify a candidate’s skill set. But to be honest, ‘Certifications are like TAX on Software Developers’. Certifications are pretty easy to obtain and a candidate needs to simply go over some question bank or set of dumps available all over the Web! Most of them do not have practical evaluation and so, fall out of place.

Obtaining a specialized degree in Computer Science/Engineering would be far more valuable instead of getting certified! Hiring managers would actually look for experience in using a particular technology. For more info, read this.

Rain expected in the crunch-game

India’s cricket match against English side is under threat from high above. It is supposed to rain and the match maybe reduced by a few overs I believe. If it was China hosting the event, they would have surely taken care of the Clouds by using some form of chemical dispensers, as they did during the Olympic games. On the other hand, India may be happy to get away with 1 point instead of a big ZERO!

The only way England is capable of winning the match is to bat first, score more than 300 and put pressure on the famed Indian batting line up otherwise, India will have England for lunch and dinner! Smile

Serializing Objects in JSON format

Serializing data/objects using XML is quite a standard way over the Web. But, XML has it’s own set of disadvantages owing to which I tried serializing objects in JSON format. It seems .NET has in-built support for doing the same. One simply needs to use the JavaScriptSerializer class available within ‘System.Web.Script.Serialization’ namespace.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Script.Serialization; /*Add System.Web.Extension library*/

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            JavaScriptSerializer sz = new JavaScriptSerializer();

            List<Employee> empList = new List<Employee>()
                { new Employee("gaurav", 1),
                    new Employee("gauz", 2) };

            Console.WriteLine(sz.Serialize(empList));
            Console.ReadLine();
        }
    }

    class Employee
    {
        public string name;
        public int id;

        public Employee() { }

        public Employee(string Name, int ID)
        {
            this.id = ID;
            this.name = Name;
        }
    }
}

Interesting puzzle about Apples and Numbers!

My friend asked me this question earlier today.

"Arrange n^2 apples in a square. From each row find the largest one and let A be the smallest of these. From each column find the smallest one and let B be the largest of these. Which one is bigger, A or B? Give reason."

The obvious thought which crossed my mind was to replace apples with unique numbers between 1-9 in a 3×3 matrix. Also, the question itself suggested the algorithm within itself to go about and find evaluate A & B.

Case I: My immediate matrix looked like this >>

1   3   6

2   5   9

4   7   8

By following the above mentioned steps, the least value found across the maximum from each rows was 6 while the max value found across the minimum from each column was 6 again!

Case II: But when I use the matrix such as >>

1   3   9
7   8   6
5   4   2

By following the above mentioned steps, the least value found across the maximum from each rows was 5 while the max value found across the minimum from each column was 3!

Immediately I realized that, the variation is purely because of the way we distribute numbers.

In case I, I used sorted sequence of numbers while in case II, I uniformly distributed the numbers at random. Result became fairly obvious!