Skip to content

Commit 6617bbd

Browse files
committed
unit test for Calender API is added
1 parent 8c5a22f commit 6617bbd

File tree

12 files changed

+259
-0
lines changed

12 files changed

+259
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package com.eprogrammerz.examples.algorithm.general;
2+
3+
/**
4+
* Created by 542596 on 3/5/2017.
5+
*/
6+
public class MatrixRotation {
7+
public static void main(String[] args) {
8+
int[][] twoD = new int[][]{
9+
/*{1,2},
10+
{3,4}*/
11+
{1,2,3},
12+
{4,5,6},
13+
{7,8,9}
14+
};
15+
flipMatrix(twoD);
16+
for(int i = 0; i< twoD.length; i++) {
17+
for(int j = 0; j <twoD[0].length; j++) {
18+
System.out.print(twoD[i][j] + " ");
19+
}
20+
System.out.println();
21+
}
22+
}
23+
24+
private static void flipMatrix(int[][] matrix) {
25+
for(int row = 0; row < matrix.length/2; row++) {
26+
int[] singleRow = matrix[matrix.length - row -1];
27+
singleRow = flipArray(singleRow);
28+
int[] tempArr = matrix[row];
29+
tempArr = flipArray(tempArr);
30+
matrix[row] = singleRow;
31+
matrix[matrix.length - row - 1] = tempArr;
32+
}
33+
if(matrix.length % 2 != 0) {
34+
int[] midRow = flipArray(matrix[matrix.length / 2]);
35+
matrix[matrix.length / 2] = midRow;
36+
}
37+
}
38+
39+
private static int[] flipArray(int[] singleRow) {
40+
int[] reversedData = new int[singleRow.length];
41+
int i;
42+
for(i=0; i < singleRow.length; i++)
43+
{
44+
reversedData[i] = singleRow[(singleRow.length - i -1)];
45+
}
46+
return reversedData;
47+
}
48+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.eprogrammerz.examples.general.inheritance;
2+
3+
/**
4+
* Created by 542596 on 3/3/2017.
5+
*/
6+
public class AccountCalculator {
7+
public static void main(String args[]) {
8+
System.out.println(new AccountCalculator().findTotalSaving(new int[]{30,40}, new int[]{10,20}) == 500);
9+
}
10+
11+
public static int savings = 0;
12+
private static int findTotalSaving(int[] credits, int[] debits) {
13+
for(int i = 0; i < credits.length; i++) {
14+
savings += credits[i];
15+
}
16+
for (int i =0; i < debits.length; i++) {
17+
savings += debits[i];
18+
}
19+
return savings;
20+
}
21+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package com.eprogrammerz.examples.general.inheritance.drawbacks;
2+
3+
/**
4+
* Created by 542596 on 3/2/2017.
5+
*/
6+
public class InheritanceFragality {
7+
8+
public static void main(String[] args) {
9+
Square square = new Square(5);
10+
System.out.println(square.calculateArea());
11+
12+
square.setBreadth(9);
13+
System.out.println(square.calculateArea());
14+
}
15+
}
16+
17+
class Square extends Rectangle {
18+
public Square(int side) {
19+
super(side, side);
20+
}
21+
}
22+
23+
class Rectangle {
24+
private int length;
25+
private int breadth;
26+
27+
public Rectangle(int length, int breadth) {
28+
this.length = length;
29+
this.breadth = breadth;
30+
}
31+
32+
public int calculateArea() {
33+
return length * breadth;
34+
}
35+
36+
public int getLength() {
37+
return length;
38+
}
39+
40+
public void setLength(int length) {
41+
this.length = length;
42+
}
43+
44+
public int getBreadth() {
45+
return breadth;
46+
}
47+
48+
public void setBreadth(int breadth) {
49+
this.breadth = breadth;
50+
}
51+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.eprogrammerz.examples.general.inheritance.drawbacks;
2+
3+
import java.util.ArrayList;
4+
5+
/**
6+
* Created by 542596 on 3/2/2017.
7+
*/
8+
public class InheritanceISAviolate {
9+
public static void main(String[] args) {
10+
//here LSP is being violated
11+
ArrayList<Integer> integers = new Stack<>();
12+
// integers.push(); //violates the ISA relationship
13+
}
14+
}
15+
16+
class Stack<T> extends ArrayList<T>{
17+
private int stackPointer;
18+
public void push(T article) {}
19+
public T pop() { return null;}
20+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.eprogrammerz.examples.general.inheritance.drawbacks;
2+
3+
import java.util.Vector;
4+
5+
/**
6+
* Created by 542596 on 3/2/2017.
7+
*/
8+
public class InheritanceISAviolate2 {
9+
public static void main(String[] args) {
10+
Vector<Integer> myVector = new MyVector<>();
11+
// myVector.addElement();
12+
}
13+
}
14+
15+
class MyVector<T> extends Vector<T> {
16+
public void addElement(T t){}
17+
}
18+
19+
class MyVectorComp<T> {
20+
private Vector<T> vector = new Vector<T>();
21+
public void addElement(T t) {}
22+
}

src/main/java/com/eprogrammerz/examples/general/inheritance/exception/Child.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,8 @@ public class Child extends Parent {
88
public void parentMethod() {
99
System.out.println("Parent Overriden...");
1010
}
11+
12+
public final void finalMethod() {
13+
Thread thread= new Thread();
14+
}
1115
}

src/main/java/com/eprogrammerz/examples/general/inheritance/exception/Parent.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,8 @@ public class Parent {
99
public void parentMethod() throws IOException {
1010
System.out.println("In Parent...");
1111
}
12+
13+
public void finalMethod() {
14+
15+
}
1216
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.eprogrammerz.examples.testing.junitCalender;
2+
3+
/**
4+
* Created by 542596 on 3/3/2017.
5+
*/
6+
public interface CurrentDayService {
7+
int getCurrentDay();
8+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.eprogrammerz.examples.testing.junitCalender;
2+
3+
import java.util.Calendar;
4+
5+
/**
6+
* Created by 542596 on 3/3/2017.
7+
*/
8+
public class CurrentDayServiceImpl implements CurrentDayService {
9+
@Override
10+
public int getCurrentDay() {
11+
Calendar calendar = Calendar.getInstance();
12+
return calendar.get(Calendar.WEEK_OF_MONTH);
13+
}
14+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.eprogrammerz.examples.testing.junitCalender;
2+
3+
/**
4+
* Created by 542596 on 3/3/2017.
5+
*/
6+
public class DateManipulator2 {
7+
}

0 commit comments

Comments
 (0)