Gaurav Khurana
BAN USERCan you give one more example ? not able to understand what is zig zag here?
- Gaurav Khurana June 09, 2013Assuming its an elevator used in malls,airport,public places
1)When no person is there on elevator,check the speed
2)When there are average nbr of perons,
3) When more than the specified limit
4)Check the emergency stop functionality
5)Working for both the directions(upward,downward) equally
6)What if stopped by power failure
1) Provide negative values then conditions like (a+b <= c) will fail to check
2) Provide floating values also a=2.3,b=2.8 then if you took as integer then a==b, but logically wrong
1) Give a very large size(1000000000) and check if its able to allocate
2) Provide number values 1,3,0,100
3) Give a character in size to api
4) GIve blank spaces
5) NUll value for size field in api
6) Call the api from multiple sessions
---> Check internet connection in network settings,may be network cable got detached
---> Check if any proxy settings ,, will set it to all defaults
---> Will try some LAN sites if they are working
@chirag
Re-installation should not be one of the point, when you have the option for contacting Dev
if you mean reinstallation of new build then its fine
Basically what we are doing is comparing the first element of both sorted portion
Scenario 1) in case second portion elemnt is smaller , we are bringing it to front and shifting the elements to right making room for it
Scenario 2) in case first portion elemnt is smaller, just goto second element in first portion, remain at first element in second portion
1,3,6,8,-5,-2,3,8
-5,1,3,6,8,-2,3,8
-5,-2,1,3,6,8,3,8
-5,-2,1,3,6,8,3,8
-5,-2,1,3,3,6,8,8
detail explanation
array length = 8
i = 0 ;
j = length/2; => 4
indices 0 1 2 3 4 5 6 7
values 1 3 6 8 -5 -2 3 8
compare if (a[i] > a[j]) i.e a[0] and a[4] ( 1 > -5 in our example)
place a[j] in a[i] and shift every indices by one
i.e. each a[i+1]= a[i] till a[j];
i++, j++
indices 0 1 2 3 4 5 6 7
values -5 1 3 6 8 -2 3 8
now compare a[1] with a[5] ( 1 > -2) , replace a[1] with a[5] ans shift
indices 0 1 2 3 4 5 6 7
values -5 -2 1 3 6 8 3 8
i++, j++;
compare a[2] with a[6] this time a[i] < a[j], no swap and shifting is required, but dont increase j only i
indices 0 1 2 3 4 5 6 7
values -5 -2 1 3 6 8 3 8
i++; j is not increased
now a[3] with a[6] still a[3] is less than a[6] so increase i only
indices 0 1 2 3 4 5 6 7
values -5 -2 1 3 6 8 3 8
now a[4] with a[6], swap and shift, we get
indices 0 1 2 3 4 5 6 7
values -5 -2 1 3 3 6 8 8
i++, j++
now a[5] with a[7], no change required, increase only i;
similalry done
i++ , ++i are equal when they are the single statement of code in a line
i mean
i++;or
++i;
But they will create a difference when used in an expression like below
++i is better in following condition
sum = ++i + (i++) + (i++);
sum = ++i + (++i) + (++i);
when you have such type of expression it(post increment) makes things complex as such things will depend on compiler.
if you want straight forward logic i = i+1, ++i would be more useful.
because if you see two expression written above, i++ would makes result different because post increment will not make i = i+1 in the same line but next
I believe this approach will work only if the we need to compare two file for same contents, But here the problem statement says that whatever secondary have should be present in primary
But the above 3 line solution will not work if primary contains extra thing or repeated values
secondary pimary
abc def
xyz abc
def xyz
abc
stu
now if you sort these files
secondary primary
abc abc
def abc
xyz def
stu
xyz
so in this case , it wont work
I think grep will not help because it might be the case that your file(Secondary) is having "abc" in first line and primary file may have xyzabc)
so if you grep abc in primary file ,, it will return true because abc is there as xyzabc
in this case files are not same, we need to check that file should not contain anything extra ,,
/home/gkhurana> cat > primary
abc
lmn
xyz
/home/gkhurana> cat > secondary
xyz
abc
lmn
/home/gkhurana> perl
# The logic is , we will read first line of secondary and then compare with each line of primary
# if there is a match its fine that means that line exist in primary,
# similary you will proceed for each line of secondary
#
# Suppose the line is not there in primary, then it will se
#
#
open fh,"secondary";
$count=1;
foreach $sec (<fh>)
{
open fh1,"primary";
$found = 1;
print "\nsecondary line=$sec";
print "\nStarting Matching in primary file\n";
foreach $pr (<fh1>)
{
print "primary line=$pr";
if($sec eq $pr) #checking if secondary line is present in primary
{
print "Match found for line $count in primary\n";
$found = 0;
}
}
close(fh1);
if($found eq '1') #if a line is in secondary and not found in primary just exit, no need to check further
{
print "\n There is content that is present in secondary but not in primary\n.";
exit(0);
}
$count++;
}
close(fh);
if($found eq '0')
{
print "\n Whatever is there in secondary is present in primary.\n ";
}
^D
secondary line=xyz
Starting Matching in primary file
primary line=abc
primary line=lmn
primary line=xyz
Match found for line 1 in primary
secondary line=abc
Starting Matching in primary file
primary line=abc
Match found for line 2 in primary
primary line=lmn
primary line=xyz
secondary line=lmn
Starting Matching in primary file
primary line=abc
primary line=lmn
Match found for line 3 in primary
primary line=xyz
-------------------------
when the files dont match, we have added def in secondary file which is not there in primary
home/gkhurana> cat > secondary
abc
lmn
xyz
def
/home/gkhurana>
secondary line=abc
Starting Matching in primary file
primary line=abc
Match found for line 1 in primary
primary line=lmn
primary line=xyz
secondary line=lmn
Starting Matching in primary file
primary line=abc
primary line=lmn
Match found for line 2 in primary
primary line=xyz
secondary line=xyz
Starting Matching in primary file
primary line=abc
primary line=lmn
primary line=xyz
Match found for line 3 in primary
secondary line=def
Starting Matching in primary file
primary line=abc
primary line=lmn
primary line=xyz
There is content that is present in secondary but not in primary
/home/gkhurana>
i hope it helps
An example of three kinds of variables
/home/gkhurana> perl
#Scalar
print "\nPrinting scalar\n";
$a = "10";
$b = "HI how are you ";
print $a;
print "\n";
print $b;
print "\n";
#Array
print "\nPrinting array values";
@a=(1,2,3,4);
@b=("do","you","know","me");
@c=('do','you');
foreach(@a,@b,@c)
{
print "$_\n";
}
#hash
%a = ( 1 =>'one' , 2=>"two");
print "\nPrinting Hash\n";
while (($key, $value)=each %a)
{
print "keys = $key value = $value \n";
}
^D
#Output below
Printing scalar
10
HI how are you
Printing array values1
2
3
4
do
you
know
me
do
you
Printing Hash
keys = 1 value = one
keys = 2 value = two
/home/gkhurana>
Repmylakleinm, Quality Assurance Engineer at Coupon Dunia
Articulate and accomplished admin executive experience at keeping an office running smoothly. A communicator and collaborator who is efficient in ...
check for floating and integer together such 1.0 & 1.1
- Gaurav Khurana June 09, 2013