• Skip to primary navigation
  • Skip to content
  • Skip to primary sidebar
  • Skip to secondary sidebar

GoHired

Interview Questions asked in Google, Microsoft, Amazon

Join WeekEnd Online Batch from 4-April-2020 on How to Crack Coding Interview in Just 10 Weeks : Fees just 20,000 INR

  • Home
  • Best Java Books
  • Algorithm
  • Internship
  • Certificates
  • About Us
  • Contact Us
  • Privacy Policy
  • Array
  • Stack
  • Queue
  • LinkedList
  • DP
  • Strings
  • Tree
  • Mathametical
  • Puzzles
  • Graph

Test Cases for Round Function

July 27, 2014 by Dhaval Dave

Write the test data for the function which takes input value as floating number and precision. It returns the output by rounding the value nearest to precision value.
e.g roundOff (3.4567,2) output will be 3.46.

To write Test Cases
1) Try to figure out the code or pseudo code
2) There can be several kind of testing but for simple question
a. Positive Test Case (where code should result output)
b. Negative Test Case (try to generate wrong output from code )
c. Destructive Test Case ( Try to generate Error )

Thanks to Dhaval for suggesting this  code,  testcases and Article

Sample Code :

#include <stdio.h>
#include <math.h>

float round1 ( float num , int n){
    float temp, dec;
    num = num < 0 ? num - (1 / pow(10,n)) : num + 1 / pow(10,n);
    num = num * pow (10 , n );

    return (int) num / pow ( 10 , n );
}
int main(){
int n = 2;
printf("n %f ",round1( 4.4567 , n ) );
return 0;
}

This may not be the perfect code but for testcases lets take this code.
Now
Test cases :
Think
1. Input/Output Tests
a)  if we give very large number to be stored in float number then ?
b) what if “n” is 0
c) what if n is too large to accommodate in int ? eg n =111000000000; (Boundry Value tests)
e) what if n is negative ?
f) Consider instead of numbers 4.4567 and n, String is passed. eg (4.456×7 , 2a)

2. Black box testing :  check proper (desired) output is printed // black box testing.

3. Stress Test
: What if this function get called by 10000 times together.

4.
 Destructive Test : what if pow(10,n) or any mathematical step gives memory error ?
a) n is too large to generate pow (10,n) :  eg n = 10
b) Both  “n” and “num”  are proper but num = num * pow (10 , n ); can generate exeception
for round1(234244.45672,5);
c) same for “Division”
solution : Keep Try Catch block to handle exception and errors

Please Give ur feedback below and share information.

Similar Articles

Filed Under: Flipkart Interview Questions, Interview Questions, problem Tagged With: testing

Reader Interactions

Primary Sidebar

Join WeekEnd Online/Offline Batch from 4-April-2020 on How to Crack Coding Interview in Just 10 Weeks : Fees just 20,000 INR

Join WeekEnd Online/Offline Batch from 4-April-2020

WhatsApp us

Secondary Sidebar

Custom Search

  • How I cracked AMAZON
  • LeetCode
  • Adobe
  • Amazon
  • Facebook
  • Microsoft
  • Hacker Earth
  • CSE Interview

Top Rated Questions

robot standing at first cell of an M*N matrix. It can move only in two directions, right and down. In how many ways, it can reach to the last cell i.e. (M, N) Code it

BlueStone E-commerce Interview Experience

C++ OOPs Part2

Find loop in Singly linked list

Client Server C program

N teams are participating. each team plays twice with all other teams. Some of them will go to the semi final. Find Minimum and Maximum number of matches that a team has to win to qualify for finals ?

Python String and numbers

Flipkart SDET Interview Experience

1014 Practice Question of New GRE – Princeton

Find the element that appears once others appears thrice

‘N’ Story Building, with 1,2,3 steps how many ways can a person reach top of building.

Coin Collection Dynamic Programming

Find min element in Sorted Rotated Array (With Duplicates)

Linked List V/S Binary Search Tree

Maximum difference between two elements s.t larger element appears after the smaller number

K’th Largest Element in BST when modification to BST is not allowed

Leetcode: Edit Distance

Advanced SQL Injection

Handle duplicates in Binary Search Tree

Printing each word reverse in string

Find the number ABCD such that when multipled by 4 gives DCBA.

TicTacToe Game As Asked in Flipkart

Find Pythagorean Triplets in an array in O(N)

Get Minimum element in O(1) from input numbers or Stack

N Petrol bunks or City arranged in circle. You have Fuel and distance between petrol bunks. Is it possible to find starting point so that we can travel all Petrol Bunks

Word Break Problem

building with N steps, we can take 1,2,3 steps calculate number of ways to reach at top of building

Find min element in Sorted Rotated Array (Without Duplicates)

Add Sub Multiply very large number stored as string

Binary Tree in Java

Copyright © 2025 · Genesis Framework · WordPress · Log in