You are on page 1of 16

Assignment 1

Task 1:

a The fault is the last element in the array is not included.


for(int i = 0; i < arr.length; i++)
b Input: arr = {4, 5, 0}
Expected output: 3
Actual output: 3.
Because the zero doesn’t affect the final output.
c Input: arr = {4, 5, 0}
Expected output: 3
Actual output: 3.
Because the program counter will be at (double average = sum / arr.length) but it
should be at (sum += arr[i]).

d Input: arr= {4,5,6}


Expected output: 5
Actual output: 3
Because the final output is wrong.
e State is arr = {90.5, -65.0, 72.25}
sum = 25.5
Average = 8.5

Task 2:
● Determine Characteristics :
❖ Step 1 : identifty
adjacentHash(String hash,Direction direction)
Returns hash of adjacent hash
parameter:
hash : string hash relative to which the adjacent
is returned
direction : direction relative to hash for which
the adjacent is returned

right(String hash)
Returns the adjacent hash to the right (east).
Parameters:
hash : to check

left(String hash)

Returns the adjacent hash to the left (west)

Parameters:

hash : origin

top(String hash)

Returns the adjacent hash to the top (north).

Parameters:

hash - origin

bottom(String hash)

Returns the adjacent hash to the bottom (south).

Parameters:

hash - origin

djacentHash(String hash,Direction

direction,int steps)
Returns the adjacent hash N steps in the given Direction

Parameters:

hash - origin hash

direction - to desired hash

neighbours(String hash)

Returns a list of the 8 surrounding hashes for a given hash in order left
Parameters:
hash - source

encodeHash(double latitude,double longitude)

Returns a geohash of length MAX_HASH_LENGTH (12)

Parameters:

latitude - in decimal degrees (WGS84)

longitude - in decimal degrees (WGS84)

encodeHash(LatLong p,int length)

Returns a geohash of given length for the given WGS84 point.


Parameters:

p - point

length - length of hash

encodeHash(LatLong p)
Returns a geohash of of length MAX_HASH_LENGTH (12)

Parameters:

p - point

encodeHash(double latitude,double longitude,int

length)

Returns a geohash of given length

Parameters:

latitude - in decimal degrees (WGS84)

longitude - in decimal degrees (WGS84)

length - length of desired hash

decodeHash(String geohash)
Returns a latitude,longitude pair as the centre of the given geohash.

Parameters:

geohash - hash to decode

hashLengthToCoverBoundingBox(double

topLeftLat,double topLeftLon,double

bottomRightLat,double bottomRightLon)
Returns the maximum length of hash that covers the bounding box.

Parameters:

topLeftLat - latitude of top left point (north west)

topLeftLon - longitude of top left point (north west)


bottomRightLat - latitude of bottom right point (southeast)

bottomRightLon - longitude of bottom right point (south

east)

hashContains(String hash,double lat,double

lon)
Returns true if and only if the bounding box corresponding to the hash contains the

given lat and long.

Parameters:

hash - hash to test containment in

lat - latitude

lon - longitude

overBoundingBox(double topLeftLat,double

topLeftLon,double bottomRightLat,double

bottomRightLon)
Returns the result of coverBoundingBoxMaxHashes with a maxHashes value of

GeoHash

Parameters:

topLeftLat - latitude of top left point (north west)

topLeftLon - longitude of top left point (north west)

bottomRightLat - latitude of bottom right point (south

east)

bottomRightLon - longitude of bottom right point (south

east)

coverBoundingBoxMaxHashes(double topLeftLat,

double topLeftLon,double bottomRightLat,double


bottomRightLon,int maxHashes)
Returns the hashes that are required to cover the given bounding box

Parameters:

topLeftLat - latitude of top left point (north west)

topLeftLon - longitude of top left point (north west)

bottomRightLat - latitude of bottom right point (south east)

bottomRightLon - longitude of bottom right point (south east)

maxHashes - maximum number of hashes to use to cover the box

coverBoundingBox(double topLeftLat,double

topLeftLon,double bottomRightLat,double

bottomRightLon,int length)
Returns the hashes of given length that are required to cover the given bounding box.

Parameters:

topLeftLat - latitude of top left point (north west)

topLeftLon - longitude of top left point (north west)

bottomRightLat - latitude of bottom right point (south east)

bottomRightLon - longitude of bottom right point (south east)

length - of hash

heightDegrees(int n)
Returns height in degrees of all geohashes of length n

Parameters:

n - length of geohash

widthDegrees(int n)

Returns width in degrees of all geohashes of length n. Results are deterministic and cached to
increase performance (might be unnecessary, have not benchmarked).
Parameters:

n - length of hash

gridAsString(String hash,int size,Set<String>


highlightThese)

Returns a String of lines of hashes to represent the relative positions of hashes on a map

Parameters:

hash - central hash

size - size of square grid in hashes

highlightThese - hashes to highlight

gridAsString(String hash,int fromRight,int


fromBottom,int toRight,int toBottom)

Returns a String of lines of hashes to represent the relative positions of hashes on a map.

Parameters:

hash - reference hash

fromRight - top left of the grid in hashes to the right (can be

negative).

fromBottom - top left of the grid in hashes to the bottom (can be

negative).

toRight - bottom righth of the grid in hashes to the bottom (can be

negative).

toBottom - bottom right of the grid in hashes to the bottom (can be

negative).
gridAsString(String hash,int fromRight,int
fromBottom,int toRight,int toBottom,Set<String>
highlightThese)

Returns a String of lines of hashes to represent the relative positions of hashes on a map.

Parameters:

hash - reference hash

fromRight - top left of the grid in hashes to the right (can be

negative).

fromBottom - top left of the grid in hashes to the bottom (can be

negative).

toRight - bottom righth of the grid in hashes to the bottom (can be

negative).

toBottom - bottom right of the grid in hashes to the bottom (can be

negative).

highlightThese - hashes to highlight

❖Step 2 : Develop Characteristic

methods params Returns values Excepti ChID charac- Covered


on istic by

adjacen Hash String hash Illegal C1 validHa -


tHash directi Argumen shLengt
on t h
C2 NotNull
Directi
on

right String String hash Illegal - - C1


Argumen
t

left String String hash Illegal - - C1


Argumet
bottom String String hash Illegal - - C1
Argumet

top String String hash Illegal - - C1


Argumen
t

adjacen String String hash Illegal - - C1


tHAsh Directi Argumen C2
on t
Integer

encodHa Double ٍString hash Illegal C3 validLa


seh double Argumen titude
t

encodeH Latlong String hash Illegal C4 NotNull C1


ash integer Argumen Latlong
t

encodeH Double String hash Illegal – - C1


ash Double Argumen C3
integer t

encodeH Latlong String hash Illegal - - C4


ash Argumen
t

❖ Step 3 : Design Partitioning

ID Char adja right left bott top adja enco enco enco enco part-
cent om cent deH deH deH deH itioning
Has Has ash ash ahs ash
h h

C1 val x x x x x x x x {1=<x<=12
idH ,x>12,
ash x<1
Len }
g

C2 Not x x {true,false}
Nul
lDi
rec
tio
n
C3 val x x {-90-
idL <x<=90,
ati x<-90,
tud x>90
e }

C4 Not x x {true,false}
Nul
l
Lat
lon
g

❖ Using each choice Coverage criterion


❖ Define Test Requirement

Method charac- TR infeasib revised- #TR


istic leTR TR
adjacen C1 {(1=<x 6
tHash C2 <=12,L (value> (value>
EFT), 12,RIG 12,RIG
HT), HT),
(x<1,N
ULL), ->
(value>
(x>12,R 12,NUL
IGHT), L),
(1=<x<
=12,Rig
ht),
(1=<x<
=12,Bot
tom),
(1=<x<
=12,To
p)
}
left C1 {=1<x< none n/a 3
=12,x>1
2,x<1
}
right C1 {=1<x< none n/a 3
=12,x>1
2,x<1
}
bottom C1 {=1<x< none n/a 3
=12,x>1
2,x<1
}
top C1 {=1<x< none n/a 3
=12,x>1
2,x<1
}
adjacen C1 {(1=<x 6
tHash C2 <=12,B (x>12, (x>12,
OTTO Left, Left,
M,step
>=0), step>= step>=
0) 0)
(x<1,N
ULL, ->
step<0)
, (x>12,

(x>12,L Null,
eft,
step>= step>=
0), 0)
(1=<x<
=12,TO
P,
step<0)
,
(1=<x<
=12,Rig
ht,
step>=
0),
(1=<x<
=12,RI
GHT,
step<0)
}
encode C3 {- none n/a 3
Hash 90=<x<
=90,x>
90,x<-
90}
encode C1 none n/a 3
Hash C4 {
(1=<x<
=12,Tru
e),
(x<1,Fal
se),
(x>12,F
alse),
}
encode C1 none n/a 3
Hash C3 {
(1=<x<
=12,-
90=<lat
<=90),
(x<1,lat
<-90),
(x>12,la
t>90),
}
encode C4 {true,fa none n/a 2
Hash lse}

1- testAdjacentHash:
We will partition the hash to three partitions:
- When the string is empty.
- When the string is of length >= 1 and <= 12.
- When the string is of length > 12.
We will partition the input space of the direction on four spaces:
- When the direction is high.
- When the direction is low.
- When the direction is left.
- When the direction is right.
2- testAdjacentHash2:
We will partition the hash to three partitions:
- When the string is empty.
- When the string is of length >= 1 and <= 12.
- When the string is of length > 12.
We will partition the input space of the direction on four spaces:
- When the direction is high.
- When the direction is low.
- When the direction is left.
- When the direction is right.
We will partition the input space of steps to three parts:
- When the steps are positive (like 2).
- When the steps are negative (like -2).
- When the steps are zero.
- When the steps are 1 because it’s a boundary value.
- When the steps are -1 because it’s a boundary value.
3- testCoverBoundingBoxMaxHashes:
We will partition each input to the following partitions:
- When the value is positive.
- When the value is negative.
- When the value is zero.
4- testLeft:
We will partition the hash to three partitions:
- When the string is empty.
- When the string is of length >= 1 and <= 12.
- When the string is of length > 12.
5- testRight:
We will partition the hash to three partitions:
- When the string is empty.
- When the string is of length >= 1 and <= 12.
- When the string is of length > 12.
6- testBottom:
We will partition the hash to three partitions:
- When the string is empty.
- When the string is of length >= 1 and <= 12.
- When the string is of length > 12.
7- testTop:
We will partition the hash to three partitions:
- When the string is empty.
- When the string is of length >= 1 and <= 12.
- When the string is of length > 12.
8- testCoverBoundingBox:
We will partition each input(integer or double) to the following partitions:
- When the value is positive or zero.
- When the value is negative.
9- testCoverBoundingBox2:
We will partition each input(integer or double) to the following partitions:
- When the value is positive or zero.
- When the value is negative.
10- testDecodeHash:
We will partition the hash to three partitions:
- When the string is empty.
- When the string is of length >= 1 and <= 12.
- When the string is of length > 12.
11- testEncodeHash:
We will partition each input to the following partitions:
- When the value is positive.
- When the value is negative.
- When the value is zero.
We will partition the longitude and latitude into:
- When the value is between -90 and 90.
- When the value is greater than 90.
- When the value is less than -90.
12- testEncodeHash2:
We will partition each input to the following partitions:
- When the value is positive.
- When the value is negative.
- When the value is zero.
13- testEncodeHash3:
We will partition each input to the following partitions:
- When the value is positive.
- When the value is negative.
- When the value is zero.
14- testEncodeHash4:
We will partition each input to the following partitions:
- When the value is positive.
- When the value is negative.
- When the value is zero.
15- testGridAsString:
We will partition each integer input to the following:
- When the input is positive or zero.
- When the input is negative.
16- testGridAsString2:
We will partition each integer input to the following:
- When the input is positive or zero.
- When the input is negative.
17- testGridAsString3:
We will partition each integer input to the following:
- When the input is positive or zero.
- When the input is negative.
18- testHashContains:
We will partition the hash to three partitions:
- When the string is empty.
- When the string is of length >= 1 and <= 12.
- When the string is of length > 12.
We will partition the integer inputs into two partitions:
- When the input is positive or zero.
- When the input is negative.
We will partition the output into two partitions:
- When the hash doesn’t contain the location.(false)
- When the hash contains the location.(true)
19- testHashLengthToCoverBoundingBox:
We will partition the integer inputs into two partitions:
- When the input is positive or zero.
- When the input is negative.
We will partition the output to two partitions:
- When the output length is from 1 to 12.
- When the output length is greater than 12.
20- testHeightDegrees:
We will partition the input to two partitions:
- When the input is from 1 to 12.
- When the input is greater than 12.
21- testWidthDegrees:
We will partition the input to two partitions:
- When the input is from 1 to 12.
- When the input is greater than 12.
22- testNeighbours:
We will partition the input to two partitions:
- When the input length is from 1 to 12.
- When the input length is greater than 12.

You might also like