Monthly Archives: August 2017

HackerRank.com 30 Days of Code – Day 3: Intro to Conditional Statements

Here is my solution to HackerRank.com’s 30 days of code challenge, day 3. This is a basic introduction to conditional statements which I found a bit easy. My main take away from this was ensuring the quality of the input by making sure that the the input values were within the correct range and wrapping that conditional statement around the other application logic statements. It doesn’t make sense to continue on processing the input if it is not within the acceptable bounds.

import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
   
   public static void main(String[] args) {
      Scanner scan = new Scanner(System.in);
      int n = scan.nextInt(); 
      scan.close();
      String ans="";
      
      //make sure n is within the constraints (between 1 and 100 inclusive)
      if( n < 1 || n > 100){
          ans="";
      }
      else
      {
          // if 'n' is NOT evenly divisible by 2 (i.e.: n is odd)
          if(n%2==1){
             ans = "Weird";
          }
          else //cover all of the even cases
          {
             //if n is between 2 and 5 inclusive 
             if(n >= 2 && n <= 5){ ans = "Not Weird"; } //if n is between 6 and 20 inclusive if(n >= 6 && n <= 20){ ans = "Weird"; } //if n is greater than 20 if(n > 20){
                 ans = "Not Weird";
             }
              
             /*
             If  is even and in the inclusive range of 2 to 5, print Not Weird
             If  is even and in the inclusive range of 6 to 20, print Weird
             If  is even and greater than 20, print Not Weird
             */
          }   
      }
       

      System.out.println(ans);
   }
}

Google’s Test-Driven Development Process

Google has innovated a testing strategy that is different than the traditional testing approach seen at other companies. This new approach comes with benefits and drawbacks that need to be managed in order to effectively incorporate the testing methodologies in an organization. While Google’s approach to testing/quality can be replicated in other organizations, it may be smart to review an organization’s culture while implementing a strategy to improve software quality.

Google has a variety of differences from a traditional software organization, but the three I find most important are:

  1. They treat development and testing as the same discipline. Both of which are focused on engineering quality into software from the ground up.
  2. They divide their software developers into three distinct roles, each of which have equal development skillsets: Software Engineers (SWEs), Software Engineers in Test (SETs), and Test Engineers (TEs).
  3. And their organizational structure prioritizes testing by having a separate testing organization within Google that loans SET and TE resources to product development groups.

Quality is not the same as testing (Whittaker, Arbon, & Carollo, 2012). Google uses this mentality along with test-driven development to engineer quality software as free from defects as possible which is one of the benefits of their process. Software Developers writing their own tests ensure that the people that know the code are the ones to debug it while they are adding features. It falls on the Test Engineers to ensure that not only the features work at a high level (an end user level) but also that the features fulfill the needs of a client. Having a separate testing organization within Google helps not only ensure that the Test Engineers have a depth of knowledge across the company’s software portfolio but it helps remove the information silos. For example, a Test Engineer that works on that works on Google Chrome may transfer to the YouTube team and share their experiences and best practices with the new team so they can adopt new processes and improve their continuous integration process.

Downfalls of Google’s approach to testing include losing quality Test Engineers to other software projects in the organization. Losing a team member that provides a certain level of product knowledge could potentially cause an impact on the product. Another risk of Google’s using approach is in the implementation of the process itself. An organization needs to have quality as a key focus from C-level management down, otherwise any issues that come with change within the organization (changing daily duties, changing HR’s perception of the testing role in the organization and raise their compensation to match Software Engineers, ect). This is reminiscent of what Patrick Copeland’s struggle to implement change to his feature developer and testing teams receiving push-back from the engineers who had their own personal concerns with changes to the day-to-day operations (Whittaker, Arbon, & Carollo, 2012). He was able to overcome the challenge in order to develop Google’s current testing practices that student’s study to this day.

While Google’s exact testing approach can be copied to other organizations it is important to remember that not every organization is the same. It is likely a better strategy to learn Google’s process and how to best incorporate certain features of their approach to one’s own organization.

Works Cited

Whittaker, J., Arbon, J., & Carollo, J. (2012). How Google Tests Software. Upper Saddle River, NJ, USA: Addison-Wesley.

 


Tolerability of Software Defects Across Industries

When analyzing software testing/bug tracking through a Priority/Severity matrix the same defect can be categorized differently depending on the industry and product of the project (Nadig, 2017). While different organizations might use different terms or levels of classification, the terms here will be defined in four categories. In this post, I will take a look at the definitions of labels used for defects and some examples across industry.

Priority determines how quickly the defect turnaround time must be (Nadig, 2017). Four categories that can be used to determine defect priority levels are:

  • P1 – Showstopper
  • P2 – Critical
  • P3 – Major
  • P4 – Minor

A defect’s Severity reflects how critical the defect is and what the impact of the defect is on the entire system’s functionality (Nadig, 2017). Four categories for labeling the severity of a defect are:

  • S1 – Showstopper
  • S2 – Severe
  • S3 – Moderate
  • S4 – Minor

A content-based website, such as one for MIT’s Math Department, may label accessibility and responsive design issues as P3/S4 which means it is should be fixed soon, but not if there are higher order defects to fix. A news organization like CNN may categorize a defect that causes only the first 1,000 articles to be displayed in their paginated list of articles as P3/S4 assuming the articles can still be found via searching their site. The older articles are less likely to be browsed to and they likely do not bring in as much ad revenue as more recent and timely articles so they do not represent a threat/risk to management.

On the other hand, MIT’s Math Department may consider a typo in a professor’s name, title, or credentials to be a P1/S2 since not only the internal faculty would not be happy about the issue, but their site is one way that they drive funding to the organization as a whole and in the organization’s eyes typos/not correctly advertising their faculty’s experience can hamper their efforts. CNN may classify a misconfiguration that causes their SSL certificate to appear as invalid to be a P1/S1 defect because the issue can lower a site’s PageRank score and lower the results in search engine listings causing revenue loss.

A tolerable (P3/P4 and S3/S4) defect for a financial website may be a website styling issue or responsive design. A credit union account I have has a non-responsive website and iOS app that displays all of my account information but none of the text is aligned and it is just a poor experience.  These are obviously things that should be fixed but the main function of the site and app are to convey my account information on demand which is why I still use them. A tolerable defect for tax preparation software may be a functionality issue where the user needs to click the ‘Next’ button twice to progress to the next step in the process. The user would likely expect to need to click a button once, but the software can still generate correct returns so it is not a showstopper.

If a financial website for a credit union could only accept a maximum 10 concurrent connections that could be considered a P1/S1 defect. An issue like this should not only be under automated testing, but it may stem from the development environment not being tested in a similar environment to production. To mitigate this, all configuration and deployment scripts should be kept in the source code management and optimally systems would be configured with tools such as Puppet to ensure testing environments were similar to production.

A medical device maker may consider an issue where the unit does not turn itself off after use a P4/S3 defect because it does not halt the use or usefulness of the product. A showstopper defect could be one that causes the device to function normally but not provide any output to the end user, definitely a P1/S1 defect. A defect of this caliber would render the device essentially useless, such as the recent string of smart lock and smart TV devices where silent firmware updates caused the main feature of the devices to stop functioning which enraged the end users.

A car navigation system may have a tolerable defect of not being able to show a user’s saved home address as hopefully the user will be able to remember their address to enter it manually if needed. This may be a more critical issue if a company finds that many of their end users are actually using this feature in an unexpected way. This would also be a good opportunity to document how users are currently using the feature and prioritize its implementation with their software engineering team. An example of a showstopper for a car navigation system would be one that prevents spoken audio from playing turn-by-turn navigation because this is a safety feature that prevents users from needing to take their eyes off the road.

Works Cited

Nadig, S. (2017, April 17). How to Set Defect Severity and Priority: Defect Triage Process. Retrieved August 28, 2017, from Software Testing Help: http://www.softwaretestinghelp.com/how-to-set-defect-priority-and-severity-with-defect-triage-process/


HackerRank.com 30 Days of Code – Day 2: Operators

Day 2 of HackerRank’s 30 days of code was a fairly simple task designed to teach operators.

import java.util.*;
import java.math.*;

public class Arithmetic {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        double mealCost = scan.nextDouble(); // original meal price
        int tipPercent = scan.nextInt(); // tip percentage
        int taxPercent = scan.nextInt(); // tax percentage
        double totalCostOfMeal = 0;
        double tipCost = 0;
        scan.close();
      
        // Write your calculation code here.
        totalCostOfMeal = (mealCost + (mealCost * (tipPercent/100))) * ((taxPercent/100) + 1);
        //System.out.println("mealCost: " + mealCost);
        //System.out.println("tipPercent: " + (((float)tipPercent/100) + 1));
        //System.out.println("taxPercent: " + (((float)taxPercent/100) + 1));
        tipCost = (((float)tipPercent/100) * mealCost);
        //System.out.println("tipCost: " + tipCost);
        totalCostOfMeal = (mealCost*(((float)taxPercent/100) + 1)) + tipCost;
        //System.out.println("totalCostOfMeal: " + totalCostOfMeal);
        
      
        
        // cast the result of the rounding operation to an int and save it as totalCost 
        int totalCost = (int) Math.round(totalCostOfMeal);
      
        // Print your result
        System.out.println("The total meal cost is " + totalCost + " dollars.");
    }
}

HackerRank.com Challenge – Diagonal Difference

This HackerRank challenge took some thinking. I needed to be able to accept a variable size multidimensional array, add the diagonals, and then find the absolute value of their difference. I haven’t needed to work with multidimensional arrays much in the past, so it took some working through the algorithm to ensure I was incrementing my values in the correct spots.

These challenges are great mental floss for coding while I learn Java.

 

import java.io.*;
import java.util.*;
import java.lang.Math;

public class Solution {

    public static void main(String[] args) {
        /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
        Scanner in = new Scanner(System.in);
        
        //get the value that defines the size of the input matrix
        int n = in.nextInt();
        
        int[][] numberArray = new int[n][n];
        
        String input = in.nextLine();;
        
        int currentDiagnalPosition1 = 0, currentDiagnalPosition2 = n-1;
        int runningTotal1 = 0, runningTotal2 = 0;
        
        for(int j = 0; j < n; j++)
        {       
            input = in.nextLine();
            
            for(int k = 0; k < n; k++)
            {
                String[] data = input.trim().split("\\s+");
                
                numberArray[j][k] = Integer.parseInt(data[k]);
                
                if(currentDiagnalPosition1 == k)
                {
                    runningTotal1 = runningTotal1 + numberArray[j][k];
                }
                if(currentDiagnalPosition2 == k)
                {
                    runningTotal2 = runningTotal2 + numberArray[j][k];
                }                
                
            } 
            currentDiagnalPosition1 = currentDiagnalPosition1 + 1;
            currentDiagnalPosition2 = currentDiagnalPosition2 - 1;
        }
        
        System.out.println(Math.abs(runningTotal1-runningTotal2));
       
    }
}

HackerRank.com Challenge – A Very Big Sum

In this lesson on HackerRank, I was challenged to demonstrate my knowledge of the long data type by needing to add multiple large numbers that would have caused an integer to overflow.

import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Solution {

    static long aVeryBigSum(int n, long[] ar) {
        //Setup space on the heap to store our running total
        long total = 0;
        
        //Iterate over each element in array ar adding the value to the running total in total
        for(long number : ar)
        {
            total = total + number;
        }
        
        //return the sum contained in total
        return total;
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        long[] ar = new long[n];
        for(int ar_i = 0; ar_i < n; ar_i++){
            ar[ar_i] = in.nextLong();
        }
        long result = aVeryBigSum(n, ar);
        System.out.println(result);
    }
}

HackerRank.com Challenge – Compare the Triplets

I recently completed the HackerRank.com Challenge “Compare the Triplets”. Below is the answer I submitted.

import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Solution {

    static int[] solve(int a0, int a1, int a2, int b0, int b1, int b2){
        // Complete this function
        
        int score_a = 0;
        int score_b = 0;
        
        //verify all numbers are in the appropriate range.
        if(a0 >= 1 && a0 <= 100 && 
           a1 >= 1 && a1 <= 100 && 
           a2 >= 1 && a2 <= 100 && 
           b0 >= 1 && b0 <= 100 && 
           b1 >= 1 && b1 <= 100 && 
           b2 >= 1 && b2 <= 100)
        {
            //System.out.println("All numbers in valid range");
            
            //tabulate score for a0/b0
            if(a0 > b0) 
            {
                score_a++;
            }
            else if(a0 < b0)
            {
                score_b++;
            }

            //tabulate score for a1/b1
            if(a1 > b1) 
            {
                score_a++;
            }
            else if(a1 < b1) 
            {
                score_b++;
            }              
            //tabulate score for a2/b2
            if(a2 > b2) 
            {
                score_a++;
            }
            else if(a2 < b2) 
            {
                score_b++;
            }
                    
            int[] number = {score_a, score_b};
            return number; 
        }
        else
        {
            System.out.println("The input needs to be between 1 and 100. Please correct the input and try again.");
            int[] number = {0, 0};
            return number; 
        }

    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int a0 = in.nextInt();
        int a1 = in.nextInt();
        int a2 = in.nextInt();
        int b0 = in.nextInt();
        int b1 = in.nextInt();
        int b2 = in.nextInt();
        int[] result = solve(a0, a1, a2, b0, b1, b2);
        for (int i = 0; i < result.length; i++) {
            System.out.print(result[i] + (i != result.length - 1 ? " " : ""));
        }
        System.out.println("");
        

    }
}

HackerRank.com Challenge – Simple Array Sum

Here is my submission for HackerRank.com’s Simple Array Sum challenge. In it I used a foreach loop to add all of the values located in an array and return the result.

import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Solution {

    static int simpleArraySum(int n, int[] ar) {
        // Complete this function
        int runningTotal = 0;
        
        for(int number : ar)
        {
            runningTotal = runningTotal + number;    
        }
        
        return runningTotal;
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] ar = new int[n];
        for(int ar_i = 0; ar_i < n; ar_i++){
            ar[ar_i] = in.nextInt();
        }
        int result = simpleArraySum(n, ar);
        System.out.println(result);
    }
}

HackerRank.com 30 Days of Code – Day 1: Data Types

Recently I’ve been going through the HackerRank.com 30 Days of Code course to learn Java. Below is my code for their Day 1 lesson.

After reviewing the code I think I would prefer to add some data type checking to ensure that the data accepted from scan.nextLine() is actually the data type that I expect. It passed the unit tests provided by HackerRank but I doubt this would pass negative testing in a Test Driven Development organization.

import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Solution {
	
    public static void main(String[] args) {
        int i = 4;
        double d = 4.0;
        String s = "HackerRank ";
		
        Scanner scan = new Scanner(System.in);

        /* Declare second integer, double, and String variables. */
        int j;
        double e;
        String t;

        /* Read and save an integer, double, and String to your variables.*/
        j = Integer.parseInt(scan.nextLine());
        e = Double.parseDouble(scan.nextLine());
        t = scan.nextLine();

        /* Print the sum of both integer variables on a new line. */
        System.out.println(i + j);

        /* Print the sum of the double variables on a new line. */
        System.out.println(d + e);
        
        /* Concatenate and print the String variables on a new line; 
        	the 's' variable above should be printed first. */
        System.out.println(s + t);
        scan.close();
    }
}