Coverage Report
03.jun.2010 17:24:56
measured on June 3, 2010 5:24:56 PM CEST
Description:
Name Amount
default package 1
package 1
class 4
method 68
anonymous class 5
Date Name Comment
June 3, 2010 5:24:51 PM CEST scienty.Duckworth20Test:testDuckworth20
June 3, 2010 5:24:51 PM CEST scienty.Duckworth20Test:testClearTextField
June 3, 2010 5:24:52 PM CEST scienty.Duckworth20Test:testAllTextFieldFirstinnings
June 3, 2010 5:24:52 PM CEST scienty.Duckworth20Test:testjButton0ActionActionPerformedTrue
June 3, 2010 5:24:52 PM CEST scienty.Duckworth20Test:testjButton0ActionActionPerformedFalse
June 3, 2010 5:24:53 PM CEST scienty.Duckworth20Test:testExecuteQuery
June 3, 2010 5:24:53 PM CEST scienty.Duckworth20Test:testGetJLabel1
June 3, 2010 5:24:53 PM CEST scienty.Duckworth20Test:testGetJLabel2
June 3, 2010 5:24:53 PM CEST scienty.Duckworth20Test:testGetJInOversLabel1
June 3, 2010 5:24:53 PM CEST scienty.Duckworth20Test:testGetJWicketLostLabel1
June 3, 2010 5:24:53 PM CEST scienty.Duckworth20Test:testGetJScoreLabel2
June 3, 2010 5:24:54 PM CEST scienty.Duckworth20Test:testGetJChasingLabel1
June 3, 2010 5:24:54 PM CEST scienty.Duckworth20Test:testGetJLabel0
June 3, 2010 5:24:54 PM CEST scienty.Duckworth20Test:testGetJTextField1
June 3, 2010 5:24:54 PM CEST scienty.Duckworth20Test:testGetJInOversTextField1
June 3, 2010 5:24:54 PM CEST scienty.Duckworth20Test:testGetJWicketLostTextField1
June 3, 2010 5:24:54 PM CEST scienty.Duckworth20Test:testGetJScoreTextField1
June 3, 2010 5:24:54 PM CEST scienty.Duckworth20Test:testGetJChasingTextField0
June 3, 2010 5:24:54 PM CEST scienty.Duckworth20Test:testGetJButton0
June 3, 2010 5:24:55 PM CEST scienty.Duckworth20Test:testGetJConditionMenu0
June 3, 2010 5:24:55 PM CEST scienty.DuckMathTest:testGetDenominatorValue
June 3, 2010 5:24:55 PM CEST scienty.DuckMathTest:testCalculateDlTrue
June 3, 2010 5:24:55 PM CEST scienty.DuckMathTest:testCalculateDlFalse
Statement Coverage Branch Coverage Loop Coverage Term Coverage
default package 310 / 352 88 %
37 / 64 57 %
5 / 15 33 %
0 / 66 0 %
scienty 310 / 352 88 %
37 / 64 57 %
5 / 15 33 %
0 / 66 0 %
Duckworth20 152 / 191 79 %
32 / 56 57 %
1 / 3 33 %
0 / 52 0 %
public Duckworth20() 3 / 3 100 %
0 / 0 ---
0 / 0 ---
0 / 0 ---
private void initComponents() 36 / 37 97 %
1 / 2 50 %
0 / 0 ---
0 / 2 0 %
public JButton getJClearButton1() 5 / 5 100 %
1 / 2 50 %
0 / 0 ---
0 / 2 0 %
ActionListener 1 / 1 100 %
0 / 0 ---
0 / 0 ---
0 / 0 ---
public void actionPerformed(ActionEvent event) 1 / 1 100 %
0 / 0 ---
0 / 0 ---
0 / 0 ---
public JButton getJButton0() 5 / 5 100 %
1 / 2 50 %
0 / 0 ---
0 / 2 0 %
ActionListener 1 / 1 100 %
0 / 0 ---
0 / 0 ---
0 / 0 ---
public void actionPerformed(ActionEvent event) 1 / 1 100 %
0 / 0 ---
0 / 0 ---
0 / 0 ---
public JTextField getJTextField1() 3 / 3 100 %
2 / 2 100 %
0 / 0 ---
0 / 2 0 %
public JLabel getJLabel2() 3 / 3 100 %
1 / 2 50 %
0 / 0 ---
0 / 2 0 %
public JLabel getJLabel1() 4 / 4 100 %
1 / 2 50 %
0 / 0 ---
0 / 2 0 %
public JLabel getJInOversLabel1() 4 / 4 100 %
1 / 2 50 %
0 / 0 ---
0 / 2 0 %
public JTextField getJInOversTextField1() 2 / 2 100 %
2 / 2 100 %
0 / 0 ---
0 / 2 0 %
public JTextField getJWicketLostTextField1() 2 / 2 100 %
2 / 2 100 %
0 / 0 ---
0 / 2 0 %
public JLabel getJWicketLostLabel1() 4 / 4 100 %
1 / 2 50 %
0 / 0 ---
0 / 2 0 %
public JTextField getJScoreTextField1() 2 / 2 100 %
2 / 2 100 %
0 / 0 ---
0 / 2 0 %
public JLabel getJScoreLabel2() 3 / 3 100 %
1 / 2 50 %
0 / 0 ---
0 / 2 0 %
public JLabel getJChasingLabel1() 3 / 3 100 %
1 / 2 50 %
0 / 0 ---
0 / 2 0 %
public JTextField getJChasingTextField0() 2 / 2 100 %
2 / 2 100 %
0 / 0 ---
0 / 2 0 %
public JLabel getJLabel0() 5 / 5 100 %
1 / 2 50 %
0 / 0 ---
0 / 2 0 %
public JSeparator getJSeparator0() 0 / 2 0 %
0 / 2 0 %
0 / 0 ---
0 / 2 0 %
public JSeparator getJSeparator1() 2 / 2 100 %
1 / 2 50 %
0 / 0 ---
0 / 2 0 %
public JMenuItem getJMenuItem1() 6 / 7 85 %
1 / 2 50 %
0 / 0 ---
0 / 2 0 %
ActionListener 0 / 1 0 %
0 / 0 ---
0 / 0 ---
0 / 0 ---
public void actionPerformed(ActionEvent event) 0 / 1 0 %
0 / 0 ---
0 / 0 ---
0 / 0 ---
public JMenuBar getJMenuBar0() 3 / 3 100 %
2 / 2 100 %
0 / 0 ---
0 / 2 0 %
public JMenu getJConditionMenu0() 9 / 9 100 %
1 / 2 50 %
0 / 0 ---
0 / 2 0 %
public JMenuItem getJMenuItem0() 5 / 6 83 %
1 / 2 50 %
0 / 0 ---
0 / 2 0 %
ActionListener 0 / 1 0 %
0 / 0 ---
0 / 0 ---
0 / 0 ---
public void actionPerformed(ActionEvent event) 0 / 1 0 %
0 / 0 ---
0 / 0 ---
0 / 0 ---
public static void installLnF() 0 / 4 0 %
0 / 4 0 %
0 / 0 ---
0 / 2 0 %
public static void main(String[] args) 0 / 9 0 %
0 / 0 ---
0 / 0 ---
0 / 0 ---
Runnable 0 / 7 0 %
0 / 0 ---
0 / 0 ---
0 / 0 ---
public void run() 0 / 7 0 %
0 / 0 ---
0 / 0 ---
0 / 0 ---
public void jMenuItem0ActionActionPerformed(ActionEvent event) 0 / 9 0 %
0 / 0 ---
0 / 0 ---
0 / 0 ---
public void jButtonClearActionActionPerformed(ActionEvent event) 1 / 1 100 %
0 / 0 ---
0 / 0 ---
0 / 0 ---
public void jButton0ActionActionPerformed(ActionEvent event) 16 / 16 100 %
4 / 6 66 %
0 / 0 ---
0 / 6 0 %
public void jMenuItem1ActionActionPerformed(ActionEvent event) 0 / 9 0 %
0 / 0 ---
0 / 0 ---
0 / 0 ---
public String executeQuery(int wicketLost, int currentOver) 14 / 15 93 %
2 / 4 50 %
1 / 3 33 %
0 / 2 0 %
public double getDenominatorValue(double d1, double d2) 1 / 1 100 %
0 / 0 ---
0 / 0 ---
0 / 0 ---
public double calculateDL(double denominator, int currOrChasingScore) 1 / 1 100 %
0 / 0 ---
0 / 0 ---
0 / 0 ---
public void clearTextField() 5 / 5 100 %
0 / 0 ---
0 / 0 ---
0 / 0 ---
DuckMath 6 / 6 100 %
2 / 2 100 %
0 / 0 ---
0 / 2 0 %
public double getDenominatorValue(double d1, double d2) 1 / 1 100 %
0 / 0 ---
0 / 0 ---
0 / 0 ---
public double calculateDl(double denominator, int currOrChasingScore, boolean firstInnings) 5 / 5 100 %
2 / 2 100 %
0 / 0 ---
0 / 2 0 %
Duckworth20Test 135 / 137 98 %
3 / 6 50 %
1 / 3 33 %
0 / 6 0 %
public Duckworth20Test(String name) 0 / 1 0 %
0 / 0 ---
0 / 0 ---
0 / 0 ---
public void setUp() throws Exception 3 / 3 100 %
0 / 0 ---
0 / 0 ---
0 / 0 ---
public void tearDown() throws Exception 2 / 2 100 %
0 / 0 ---
0 / 0 ---
0 / 0 ---
public final void testDuckworth20() 1 / 1 100 %
0 / 0 ---
0 / 0 ---
0 / 0 ---
public final void testClearTextField() 23 / 23 100 %
0 / 0 ---
0 / 0 ---
0 / 0 ---
public void testAllTextFieldFirstinnings() 6 / 6 100 %
1 / 2 50 %
0 / 0 ---
0 / 0 ---
public void testjButton0ActionActionPerformedTrue() 25 / 25 100 %
1 / 2 50 %
0 / 0 ---
0 / 2 0 %
public void testjButton0ActionActionPerformedFalse() 29 / 29 100 %
1 / 2 50 %
0 / 0 ---
0 / 2 0 %
public final void testExecuteQuery() 4 / 4 100 %
0 / 0 ---
1 / 3 33 %
0 / 2 0 %
public final void testGetJLabel1() 3 / 3 100 %
0 / 0 ---
0 / 0 ---
0 / 0 ---
public final void testGetJLabel2() 3 / 3 100 %
0 / 0 ---
0 / 0 ---
0 / 0 ---
public final void testGetJInOversLabel1() 3 / 3 100 %
0 / 0 ---
0 / 0 ---
0 / 0 ---
public final void testGetJWicketLostLabel1() 3 / 3 100 %
0 / 0 ---
0 / 0 ---
0 / 0 ---
public final void testGetJScoreLabel2() 3 / 3 100 %
0 / 0 ---
0 / 0 ---
0 / 0 ---
public final void testGetJChasingLabel1() 3 / 3 100 %
0 / 0 ---
0 / 0 ---
0 / 0 ---
public final void testGetJLabel0() 3 / 3 100 %
0 / 0 ---
0 / 0 ---
0 / 0 ---
public final void testGetJTextField1() 3 / 3 100 %
0 / 0 ---
0 / 0 ---
0 / 0 ---
public final void testGetJInOversTextField1() 3 / 3 100 %
0 / 0 ---
0 / 0 ---
0 / 0 ---
public final void testGetJWicketLostTextField1() 3 / 3 100 %
0 / 0 ---
0 / 0 ---
0 / 0 ---
public final void testGetJScoreTextField1() 3 / 3 100 %
0 / 0 ---
0 / 0 ---
0 / 0 ---
public final void testGetJChasingTextField0() 3 / 3 100 %
0 / 0 ---
0 / 0 ---
0 / 0 ---
public void testGetJButton0() 3 / 3 100 %
0 / 0 ---
0 / 0 ---
0 / 0 ---
public final void testGetJConditionMenu0() 3 / 3 100 %
0 / 0 ---
0 / 0 ---
0 / 0 ---
DuckMathTest 17 / 18 94 %
0 / 0 ---
3 / 9 33 %
0 / 6 0 %
public DuckMathTest(String name) 0 / 1 0 %
0 / 0 ---
0 / 0 ---
0 / 0 ---
@Before public void setUp() throws Exception 1 / 1 100 %
0 / 0 ---
0 / 0 ---
0 / 0 ---
@After public void tearDown() throws Exception 1 / 1 100 %
0 / 0 ---
0 / 0 ---
0 / 0 ---
public final void testGetDenominatorValue() 4 / 4 100 %
0 / 0 ---
1 / 3 33 %
0 / 2 0 %
public final void testCalculateDlTrue() 6 / 6 100 %
0 / 0 ---
1 / 3 33 %
0 / 2 0 %
public final void testCalculateDlFalse() 5 / 5 100 %
0 / 0 ---
1 / 3 33 %
0 / 2 0 %
Duckworth20.java
33   public class Duckworth20 extends JFrame {
34  
35       private static final long serialVersionUID = 1L;
36       private JMenuItem jMenuItem0;
37       private JMenu jConditionMenu0;
38       private JMenuBar jMenuBar0;
39       private JMenuItem jMenuItem1;
40       private JSeparator jSeparator1;
41       private JSeparator jSeparator0;
42       private JLabel jLabel0;
43       private JTextField jChasingTextField0;
44       private JLabel jChasingLabel1;
45       private JLabel jScoreLabel2;
46       private JTextField jScoreTextField1;
47       private JLabel jWicketLostLabel1;
48       private JTextField jWicketLostTextField1;
49       private JTextField jInOversTextField1;
50       private JLabel jInOversLabel1;
51       private JLabel jLabel1;
52       private JLabel jLabel2;
53       public JTextField jTextField1;
54       private JButton jButton0;
55       public boolean firstInnings = false;
56       boolean alreadyInitialized = false;
57       private JButton jClearButton1;
58       public DuckMath dm = new DuckMath();
59       private static final String PREFERRED_LOOK_AND_FEEL = "javax.swing.plaf.metal.MetalLookAndFeel";
60       
61       public Duckworth20() {
62           setJMenuBar(getJMenuBar0());
63           setSize(616, 417);
64           initComponents();
65       }
66  
67       private void initComponents() {
68               if(alreadyInitialized){
69                   return;
70               }
71           setForeground(Color.black);
72           setFont(new Font("Dialog", Font.PLAIN, 12));
73           setLayout(new GroupLayout());
74           add(getJChasingLabel1(), new Constraints(new Leading(217, 87, 12, 12), new Leading(86, 12, 12)));
75           add(getJScoreLabel2(), new Constraints(new Leading(225, 10, 10), new Leading(124, 10, 10)));
76           add(getJScoreTextField1(), new Constraints(new Leading(291, 71, 12, 12), new Leading(122, 25, 12, 12)));
77           add(getJLabel0(), new Constraints(new Leading(22, 549, 10, 10), new Leading(10, 40, 10, 10)));
78           add(getJInOversTextField1(), new Constraints(new Leading(293, 69, 12, 12), new Leading(200, 27, 10, 10)));
79           add(getJWicketLostTextField1(), new Constraints(new Leading(291, 70, 12, 12), new Leading(162, 24, 10, 10)));
80           add(getJWicketLostLabel1(), new Constraints(new Leading(172, 87, 12, 12), new Leading(165, 12, 12)));
81           add(getJInOversLabel1(), new Constraints(new Leading(185, 69, 10, 10), new Leading(205, 12, 12)));
82           add(getJChasingTextField0(), new Constraints(new Leading(289, 74, 10, 10), new Leading(82, 24, 12, 12)));
83           add(getJLabel1(), new Constraints(new Leading(60, 202, 10, 10), new Leading(242, 32, 10, 10)));
84           add(getJLabel2(), new Constraints(new Leading(67, 192, 12, 12), new Leading(272, 10, 10)));
85           add(getJTextField1(), new Constraints(new Leading(293, 68, 12, 12), new Leading(254, 31, 10, 10)));
86           add(getJButton0(), new Constraints(new Leading(188, 158, 10, 10), new Leading(309, 10, 10)));
87           add(getJClearButton1(), new Constraints(new Leading(373, 10, 10), new Leading(309, 12, 12)));
88           jButton0.setName("Ask"); //"Ask DL Expert"
89           jTextField1.setName("PScore"); //"Projected score"
90           jInOversTextField1.setName("OC"); // "Overs completed"
91           jLabel0.setName("FirstTeam"); //"DL analysis for T20-20 Match"
92           jLabel1.setName("WP"); //"The team is in a winning posistion "
93           jLabel2.setName("SM");  //" if its score is more than"
94           jInOversLabel1.setName("In Overs"); //"In Overs"
95           jWicketLostTextField1.setName("WL"); //"Wicket lost"
96           jWicketLostLabel1.setName("WLL"); // "Wicket lost"
97           jScoreTextField1.setName("Sc"); // "Score"
98           jScoreLabel2.setName("S"); // "Score"
99           jChasingLabel1.setName("C"); //"Chasing"
100           jChasingTextField0.setName("CH"); //"Chasing"
101           //    jSeparator0.setName("S0"); //"Separator 0"
102           //    jSeparator1.setName("S1"); //"Separator 1"
103           jMenuItem1.setName("ST"); //"Second Team"
104           jMenuItem0.setName("FT"); //"First Team"
105           jMenuBar0.setName("MB");
106           jClearButton1.setName("CL");
107           //    jConditionMenu0.setName("Con");
108           setJMenuBar(getJMenuBar0());
109           setSize(616, 417);
110       }
111  
112       public JButton getJClearButton1() {
113           if (jClearButton1 == null) {
114               jClearButton1 = new JButton();
115               jClearButton1.setText("Clear ");
116               jClearButton1.addActionListener(new ActionListener() {
117  
118                   public void actionPerformed(ActionEvent event) {
119                       jButtonClearActionActionPerformed(event);
120                   }
121               });
122           }
123           return jClearButton1;
124       }
125  
126       public JButton getJButton0() {
127           if (jButton0 == null) {
128               jButton0 = new JButton();
129               jButton0.setText("Ask DL Expert");
130               jButton0.addActionListener(new ActionListener() {
131  
132                   public void actionPerformed(ActionEvent event) {
133                       jButton0ActionActionPerformed(event);
134                   }
135               });
136           }
137           return jButton0;
138       }
139  
140       public JTextField getJTextField1() {
141           if (jTextField1 == null) {
142               jTextField1 = new JTextField();
143               jTextField1.setName("PScore"); //"Projected score"
144           }
145           return jTextField1;
146       }
147  
148       public JLabel getJLabel2() {
149           if (jLabel2 == null) {
150               jLabel2 = new JLabel();
151               jLabel2.setText(" if its score is more than");
152           }
153           return jLabel2;
154       }
155  
156       public JLabel getJLabel1() {
157           if (jLabel1 == null) {
158               jLabel1 = new JLabel();
159               jLabel1.setHorizontalAlignment(SwingConstants.RIGHT);
160               jLabel1.setText("The team is in a winning posistion ");
161           }
162           return jLabel1;
163       }
164  
165       public JLabel getJInOversLabel1() {
166           if (jInOversLabel1 == null) {
167               jInOversLabel1 = new JLabel();
168               jInOversLabel1.setHorizontalAlignment(SwingConstants.RIGHT);
169               jInOversLabel1.setText("In Overs");
170           }
171           return jInOversLabel1;
172       }
173  
174       public JTextField getJInOversTextField1() {
175           if (jInOversTextField1 == null) {
176               jInOversTextField1 = new JTextField();
177           }
178           return jInOversTextField1;
179       }
180  
181       public JTextField getJWicketLostTextField1() {
182           if (jWicketLostTextField1 == null) {
183               jWicketLostTextField1 = new JTextField();
184           }
185           return jWicketLostTextField1;
186       }
187  
188       public JLabel getJWicketLostLabel1() {
189           if (jWicketLostLabel1 == null) {
190               jWicketLostLabel1 = new JLabel();
191               jWicketLostLabel1.setHorizontalAlignment(SwingConstants.RIGHT);
192               jWicketLostLabel1.setText("Wickets lost");
193           }
194           return jWicketLostLabel1;
195       }
196  
197       public JTextField getJScoreTextField1() {
198           if (jScoreTextField1 == null) {
199               jScoreTextField1 = new JTextField();
200           }
201           return jScoreTextField1;
202       }
203  
204       public JLabel getJScoreLabel2() {
205           if (jScoreLabel2 == null) {
206               jScoreLabel2 = new JLabel();
207               jScoreLabel2.setText("Score");
208           }
209           return jScoreLabel2;
210       }
211  
212       public JLabel getJChasingLabel1() {
213           if (jChasingLabel1 == null) {
214               jChasingLabel1 = new JLabel();
215               jChasingLabel1.setText("Chasing");
216               //jChasingLabel1.setVisible(false);
217           }
218           return jChasingLabel1;
219       }
220  
221       public JTextField getJChasingTextField0() {
222           if (jChasingTextField0 == null) {
223               jChasingTextField0 = new JTextField();
224           }
225           return jChasingTextField0;
226       }
227  
228       public JLabel getJLabel0() {
229           if (jLabel0 == null) {
230               jLabel0 = new JLabel();
231               jLabel0.setHorizontalAlignment(SwingConstants.CENTER);
232               jLabel0.setText("DL analysis for T20-20 Match");
233               jLabel0.setBorder(BorderFactory.createTitledBorder(null, "First Team", TitledBorder.LEFT, TitledBorder.TOP, new Font("Dialog", Font.BOLD, 12),
234                       new Color(51, 51, 51)));
235           }
236           return jLabel0;
237       }
238  
239       public JSeparator getJSeparator0() {
240           if (jSeparator0 == null) {
241               jSeparator0 = new JSeparator();
242           }
243           return jSeparator0;
244       }
245  
246       public JSeparator getJSeparator1() {
247           if (jSeparator1 == null) {
248               jSeparator1 = new JSeparator();
249           }
250           return jSeparator1;
251       }
252  
253       public JMenuItem getJMenuItem1() {
254           if (jMenuItem1 == null) {
255               jMenuItem1 = new JMenuItem();
256               jMenuItem1.setMnemonic('S');
257               jMenuItem1.setText("Second Team");
258               jMenuItem1.setName("ST"); //"Second Team"
259               jMenuItem1.addActionListener(new ActionListener() {
260  
261                   public void actionPerformed(ActionEvent event) {
262                       jMenuItem1ActionActionPerformed(event);
263                   }
264               });
265           }
266           return jMenuItem1;
267       }
268  
269       public JMenuBar getJMenuBar0() {
270           if (jMenuBar0 == null) {
271               jMenuBar0 = new JMenuBar();
272               jMenuBar0.add(getJConditionMenu0());
273           }
274           return jMenuBar0;
275       }
276  
277       public JMenu getJConditionMenu0() {
278           if (jConditionMenu0 == null) {
279               jConditionMenu0 = new JMenu();
280               jConditionMenu0.setMnemonic('C');
281               jConditionMenu0.setText("Condition");
282               jConditionMenu0.setOpaque(false);
283               jConditionMenu0.add(getJMenuItem0());
284               jConditionMenu0.add(getJSeparator1());
285               jConditionMenu0.add(getJMenuItem1());
286               jConditionMenu0.setName("Con");
287  
288           }
289           return jConditionMenu0;
290       }
291  
292       public JMenuItem getJMenuItem0() {
293           if (jMenuItem0 == null) {
294               jMenuItem0 = new JMenuItem();
295               jMenuItem0.setMnemonic('F');
296               jMenuItem0.setText("First Team");
297               jMenuItem0.addActionListener(new ActionListener() {
298  
299                   public void actionPerformed(ActionEvent event) {
300                       jMenuItem0ActionActionPerformed(event);
301                   }
302               });
303           }
304           return jMenuItem0;
305       }
306  
307       public static void installLnF() {
308           try {
309               String lnfClassname = PREFERRED_LOOK_AND_FEEL;
310               if (lnfClassname == null)
311                   lnfClassname = UIManager.getCrossPlatformLookAndFeelClassName();
312               UIManager.setLookAndFeel(lnfClassname);
313  
314           } catch (Exception e) {
315               System.err.println("Cannot install " + PREFERRED_LOOK_AND_FEEL
316                       + " on this platform:" + e.getMessage());
317           }
318       }
319  
320       /**
321        * Main entry of the class.
322        * Note: This class is only created so that you can easily preview the result at runtime.
323        * It is not expected to be managed by the designer.
324        * You can modify it as you like.
325        */
326       public static void main(String[] args) {
327           installLnF();
328           SwingUtilities.invokeLater(new Runnable() {
329               public void run() {
330                   Duckworth20 frame = new Duckworth20();
331                   //                JFrame frame = new Duckworth20();
332                   frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
333                   frame.setTitle("Duckworth Analysis T20-20");
334                   frame.getContentPane().setPreferredSize(frame.getSize());
335                   frame.pack();
336                   frame.setLocationRelativeTo(null);
337  
338                   frame.setVisible(true);
339               }
340           });
341       }
342  
343       public void jMenuItem0ActionActionPerformed(ActionEvent event) {
344           clearTextField();
345           initComponents();
346           //System.out.println("First Innings" + event.getActionCommand());
347           getJChasingLabel1().setVisible(false);
348           getJChasingTextField0().setVisible(false);
349           getJLabel1().setText("The Score after 20 Overs will be");
350           getJLabel2().setVisible(false);
351           getJLabel0().setForeground(Color.RED);
352           getJLabel0().setText("DL analysis for T20-20 Match : First Batting");
353           firstInnings = true;
354       }
355  
356       public void jButtonClearActionActionPerformed(ActionEvent event){
357           clearTextField();
358       }
359       public void jButton0ActionActionPerformed(ActionEvent event) {
360  
361           // double denominator = getDenominatorValue(2,3);
362           int currentScore = Integer.parseInt(getJScoreTextField1().getText()
363                   .trim());
364           int wicketLost = Integer.parseInt(getJWicketLostTextField1().getText()
365                   .trim());
366           int overCompleted = Integer.parseInt(getJInOversTextField1().getText());
367           String dlProj = executeQuery(wicketLost, overCompleted);
368           if (firstInnings) {
369  
370               //    System.out.println("first innings");
371               if (dlProj != null) {
372                   double d = Double.parseDouble(dlProj);
373                   System.out.println(d);
374                   double deno = getDenominatorValue(d, (56.6 - d));
375                   double projectedScore = calculateDL(deno, currentScore);
376                   NumberFormat formatter = new DecimalFormat("#0.00");
377                   getJTextField1().setText("" + formatter.format(projectedScore));
378  
379               }
380           } else {
381               int chasingScore = Integer.parseInt(getJChasingTextField0()
382                       .getText());
383               //System.out.println("second innings");
384               if (dlProj != null) {
385                   double d = Double.parseDouble(dlProj);
386                   double deno = getDenominatorValue((56.6 - d),56.6 );
387                   double projectedScore = calculateDL( deno, chasingScore);
388                   NumberFormat formatter = new DecimalFormat("#0.00");
389                   getJTextField1().setText("" + formatter.format(projectedScore));
390               }
391           }
392  
393       }
394       public void jMenuItem1ActionActionPerformed(ActionEvent event) {
395  
396           initComponents();
397           clearTextField();
398           //System.out.println("Second Innings" + event.getActionCommand());    
399           getJChasingLabel1().setVisible(true);
400           getJChasingTextField0().setVisible(true);
401           getJLabel1().setText("The team is in a winning posistion ");
402           getJLabel2().setVisible(true);
403           getJLabel0().setText("DL Analysis for a team batting Second");
404           jLabel0.setBorder(BorderFactory.createTitledBorder(null, "Second Team", TitledBorder.LEFT, TitledBorder.TOP, new Font("Dialog", Font.BOLD, 12),
405                   new Color(51, 51, 51)));
406           firstInnings = false;
407       }
408  
409       public String executeQuery(int wicketLost, int currentOver){
410           Connection con = null;
411           Statement sta = null;
412           ResultSet res = null;
413           String dwProj = null;    
414           try {
415               Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
416               con = DriverManager.getConnection("jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=etc/duckworth.accdb");
417               sta = con.createStatement();
418               String query = "select wicket"+wicketLost+ " from Duckworth t where  oversleft='"+(20-currentOver)+"'";
419               res = sta.executeQuery(query);
420               while (res.next()) {
421                   dwProj = res.getString(1);
422               }
423           }catch(Exception e){
424               e.printStackTrace();
425           }
426           finally{
427               try{
428                   res.close();
429                   sta.close();
430                   con.close();
431               }catch(Exception e){}
432           }
433           return dwProj;
434       }
435  
436       public double getDenominatorValue(double d1, double d2){
437           return dm.getDenominatorValue(d1, d2);
438       }
439  
440       public double calculateDL(double denominator, int currOrChasingScore) {
441           return dm.calculateDl(denominator, currOrChasingScore, firstInnings);
442       }
443  
444       public void clearTextField(){
445           getJChasingTextField0().setText("");
446           getJInOversTextField1().setText("");
447           getJWicketLostTextField1().setText("");
448           getJTextField1().setText("");
449           getJScoreTextField1().setText("");
450       }
451   }
DuckMath.java
3   public class DuckMath {
4  
5       public double d ;
6       public double getDenominatorValue(double d1, double d2){
7           return d1/d2;
8       }
9  
10       public double calculateDl(double denominator, int currOrChasingScore, boolean firstInnings) {
11       
12           if (firstInnings) {
13               double total = ((denominator * currOrChasingScore) + currOrChasingScore);
14               d = ((total) + total*(3.47 / 100));
15  
16           }
17           else {
18               double total = ((denominator)*currOrChasingScore);
19               d= total + total * (3.47/100);
20           }
21           return d;
22       }
23  
24   }
Duckworth20Test.java
15   public class Duckworth20Test extends TestCase {
16       private Duckworth20 duck = new Duckworth20();
17       public Duckworth20Test(String name) {
18           super(name);
19       }
20  
21       public void setUp() throws Exception {
22           super.setUp();
23           duck = new Duckworth20();
24           duck.setVisible(true);
25       }
26  
27       public void tearDown() throws Exception {
28           duck = null;
29           super.tearDown();
30       }
31  
32       public final void testDuckworth20() {
33           duck = new Duckworth20();
34       }
35  
36       //--------------------- TESTCASE NO 4 ---------------------------------//
37       public final void testClearTextField() {
38           NamedComponentFinder finder0 = new NamedComponentFinder(JComponent.class, "OC");
39           JTextField jtf0 = (JTextField)finder0.find(duck,0);
40           jtf0.setText("12");
41  
42           NamedComponentFinder finder1 = new NamedComponentFinder(JComponent.class, "WL");
43           JTextField jtf1 = (JTextField)finder1.find(duck,0);
44           jtf1.setText("8");
45  
46           NamedComponentFinder finder2 = new NamedComponentFinder(JComponent.class, "PScore");
47           JTextField jtf2 = (JTextField)finder2.find(duck,0);
48           jtf2.setText("12");
49  
50           NamedComponentFinder finder3 = new NamedComponentFinder(JComponent.class, "Sc");
51           JTextField jtf3 = (JTextField)finder3.find(duck,0);
52           jtf3.setText("200");
53  
54           NamedComponentFinder finder5 = new NamedComponentFinder(JComponent.class, "CH");
55           JTextField jtf4 = (JTextField)finder5.find(duck,0);
56           jtf4.setText("200");
57  
58           NamedComponentFinder finder4 = new NamedComponentFinder(JComponent.class, "CL");
59           JButton jb = (JButton)finder4.find(duck,0);
60           jb.doClick();
61  
62           assertEquals("",jtf0.getText());
63           assertEquals("",jtf1.getText());
64           assertEquals("",jtf2.getText());
65           assertEquals("",jtf3.getText());
66           assertEquals("",jtf4.getText());
67  
68       }
69  
70       //--------------------- TESTCASE NO 5 ---------------------------------//
71       public void testAllTextFieldFirstinnings()
72       {
73           boolean b = false;
74           try {
75               NamedComponentFinder finder = new NamedComponentFinder(JComponent.class, "Ask");
76               JButton jb = (JButton)finder.find(duck,0);
77               jb.doClick();
78           }
79           catch (NumberFormatException e) {
80               b = true; //handling exception
81           }
82           assertTrue("Getting a numberformat Expcetion", b);
83       }
84  
85       //--------------------- TESTCASE NO 6 ---------------------------------//
86       public void testjButton0ActionActionPerformedTrue() {
87           NamedComponentFinder finder0 = new NamedComponentFinder(JComponent.class, "Sc");
88           JTextField jtf0 = (JTextField)finder0.find(duck,0);
89           int currentScore = new Random().nextInt(300);
90           jtf0.setText(""+currentScore);
91  
92           NamedComponentFinder finder1 = new NamedComponentFinder(JComponent.class, "WL");
93           JTextField jtf1 = (JTextField)finder1.find(duck,0);
94           int wicketLost = new Random().nextInt(9);
95           jtf1.setText(""+wicketLost);
96  
97           NamedComponentFinder finder2 = new NamedComponentFinder(JComponent.class, "OC");
98           JTextField jtf2 = (JTextField)finder2.find(duck,0);
99           int overCompleted = new Random().nextInt(19);
100           jtf2.setText(""+overCompleted);
101  
102           NamedComponentFinder finder3 = new NamedComponentFinder(JComponent.class, "PScore");
103           JTextField jtf3 = (JTextField)finder3.find(duck,0);
104  
105           NamedComponentFinder finder = new NamedComponentFinder(JComponent.class, "Ask");
106           JButton jb = (JButton)finder.find(duck,0);
107  
108           duck.firstInnings = true;//first innings
109           jb.doClick();
110  
111           String dlProj = duck.executeQuery(wicketLost, overCompleted);
112           //first innings when if condition is true
113           if (dlProj != null) {
114               double d = Double.parseDouble(dlProj);
115               double deno = duck.getDenominatorValue(d, (56.6 - d));
116               double projectedScore = duck.calculateDL(deno, currentScore);
117               NumberFormat formatter = new DecimalFormat("#0.00");
118               jtf3.setText("" + formatter.format(projectedScore));
119           }
120           assertEquals(jtf3.getText(),duck.jTextField1.getText());
121       }
122       //--------------------- TESTCASE NO 7 ---------------------------------//
123       public void testjButton0ActionActionPerformedFalse() {
124           NamedComponentFinder finder0 = new NamedComponentFinder(JComponent.class, "Sc");
125           JTextField jtf0 = (JTextField)finder0.find(duck,0);
126           int currentScore = new Random().nextInt(300);
127           jtf0.setText(""+currentScore);
128  
129           NamedComponentFinder finder1 = new NamedComponentFinder(JComponent.class, "WL");
130           JTextField jtf1 = (JTextField)finder1.find(duck,0);
131           int wicketLost = new Random().nextInt(9);
132           jtf1.setText(""+wicketLost);
133  
134           NamedComponentFinder finder2 = new NamedComponentFinder(JComponent.class, "OC");
135           JTextField jtf2 = (JTextField)finder2.find(duck,0);
136           int overCompleted = new Random().nextInt(19);
137           jtf2.setText(""+overCompleted);
138  
139           NamedComponentFinder finder3 = new NamedComponentFinder(JComponent.class, "PScore");
140           JTextField jtf3 = (JTextField)finder3.find(duck,0);
141  
142           NamedComponentFinder finder4 = new NamedComponentFinder(JComponent.class, "CH");
143           JTextField jtf4 = (JTextField)finder4.find(duck,0);
144           int chasingScore = new Random().nextInt();
145           jtf4.setText(""+chasingScore);
146  
147           NamedComponentFinder finder = new NamedComponentFinder(JComponent.class, "Ask");
148           JButton jb = (JButton)finder.find(duck,0);
149  
150           duck.firstInnings = false;//first innings
151           jb.doClick();
152  
153           String dlProj = duck.executeQuery(wicketLost, overCompleted);
154           //Second innings when if condition is false
155           if (dlProj != null) {
156               double d = Double.parseDouble(dlProj);
157               double deno = duck.getDenominatorValue((56.6 - d),56.6 );
158               double projectedScore = duck.calculateDL( deno, chasingScore);
159               NumberFormat formatter = new DecimalFormat("#0.00");
160               jtf3.setText("" + formatter.format(projectedScore));
161           }
162           assertEquals(jtf3.getText(),duck.jTextField1.getText());
163       }
164  
165       //--------------------- TESTCASE NO 8 ---------------------------------//
166       public final void testExecuteQuery() {
167           int wicketLost []= {0,2,4,9};
168           int overCompleted[]= {2,4,17,18};
169           double expectedResult[]={52.2,44.7,10.2,3.7};
170           for (int i = 0; i < wicketLost.length; i++) {
171               assertEquals(expectedResult[i],Double.parseDouble(duck.executeQuery(wicketLost[i],overCompleted[i]) ));
172           }    
173       }
174  
175       //--------------------- TESTCASE NO 9 ---------------------------------//
176       public final void testGetJLabel1() {
177           NamedComponentFinder finder = new NamedComponentFinder(JComponent.class, "WP");
178           JLabel jl =(JLabel)finder.find(duck,0);
179           assertNotNull("Could not find winning position label", jl);
180       }
181       public final void testGetJLabel2() {
182           NamedComponentFinder finder = new NamedComponentFinder(JComponent.class, "SM");
183           JLabel jl =(JLabel)finder.find(duck,0);
184           assertNotNull("Could not find if its score is more than label", jl);
185       }
186  
187       public final void testGetJInOversLabel1() {
188           NamedComponentFinder finder = new NamedComponentFinder(JComponent.class, "In Overs");
189           JLabel jl =(JLabel)finder.find(duck,0);
190           assertNotNull("Could not find if its score is more than label", jl);
191       }
192  
193       public final void testGetJWicketLostLabel1() {
194           NamedComponentFinder finder = new NamedComponentFinder(JComponent.class, "WLL");
195           JLabel jl =(JLabel)finder.find(duck,0);
196           assertNotNull("Could not find wicket lost label", jl);
197       }
198  
199       public final void testGetJScoreLabel2() {
200           NamedComponentFinder finder = new NamedComponentFinder(JComponent.class, "S");
201           JLabel jl =(JLabel)finder.find(duck,0);
202           assertNotNull("Could not find score label", jl);
203       }
204  
205       public final void testGetJChasingLabel1() {
206           NamedComponentFinder finder = new NamedComponentFinder(JComponent.class, "C");
207           JLabel jl =(JLabel)finder.find(duck,0);
208           assertNotNull("Could not find chasing label", jl);
209       }
210  
211       public final void testGetJLabel0() {
212           NamedComponentFinder finder = new NamedComponentFinder(JComponent.class, "FirstTeam");
213           JLabel jl0 =(JLabel)finder.find(duck,0);
214           assertNotNull("Could not find FirstTeam label0", jl0);
215       }    
216  
217       //--------------------- TESTCASE NO 10 ---------------------------------//
218       public final void testGetJTextField1() {
219           NamedComponentFinder finder = new NamedComponentFinder(JComponent.class, "PScore");
220           JTextField jtf = (JTextField)finder.find(duck,0);
221           assertNotNull("Could not find Projected score textfield", jtf);
222       }
223  
224       public final void testGetJInOversTextField1() {
225           NamedComponentFinder finder = new NamedComponentFinder(JComponent.class, "OC");
226           JTextField jtf = (JTextField)finder.find(duck,0);
227           assertNotNull("Could not find overs completed textfield", jtf);
228       }
229  
230       public final void testGetJWicketLostTextField1() {
231           NamedComponentFinder finder = new NamedComponentFinder(JComponent.class, "WL");
232           JTextField jtf = (JTextField)finder.find(duck,0);
233           assertNotNull("Could not find wicket lost textfield", jtf);
234       }
235  
236       public final void testGetJScoreTextField1() {
237           NamedComponentFinder finder = new NamedComponentFinder(JComponent.class, "Sc");
238           JTextField jtf = (JTextField)finder.find(duck,0);
239           assertNotNull("Could not find current score textfield", jtf);
240       }
241  
242       public final void testGetJChasingTextField0() {
243           NamedComponentFinder finder = new NamedComponentFinder(JComponent.class, "CH");
244           JTextField jtf = (JTextField)finder.find(duck,0);
245           assertNotNull("Could not find current chasing textfield", jtf);
246       }
247  
248       //--------------------- TESTCASE NO 11 ---------------------------------//
249       public void testGetJButton0() {
250           NamedComponentFinder finder = new NamedComponentFinder(JComponent.class, "Ask");
251           JButton jb = (JButton)finder.find(duck,0);
252           assertNotNull("Could not find ask Duckworth lewis button", jb);
253       }
254  
255       //---------------------TESTCASE NO 12 ---------------------------------//
256       public final void testGetJConditionMenu0() {
257           NamedComponentFinder finder = new NamedComponentFinder(JComponent.class, "Con");
258           JMenu jmb = (JMenu)finder.find(duck,0);
259           assertNotNull("Could not find separator 0",jmb);
260       }
261   }
DuckMathTest.java
8   public class DuckMathTest extends TestCase
9   {
10       public DuckMathTest(String name) {
11           super(name);
12       }
13       @Before
14       public void setUp() throws Exception {
15           super.setUp();
16       }
17  
18       @After
19       public void tearDown() throws Exception {
20           super.tearDown();
21       }
22  
23       //--------------------- TESTCASE NO 1 ---------------------------------//
24       public final void testGetDenominatorValue() {
25           for (double i = 0; i < 100; i++) {
26               double numerator = new Random().nextDouble();
27               double denominator = new Random().nextDouble();
28               double answer =  numerator/denominator;
29               assertEquals(answer,new DuckMath().getDenominatorValue(numerator, denominator));
30           }
31       }
32  
33       //--------------------- TESTCASE NO 2 ---------------------------------//
34       public final void testCalculateDlTrue() {
35  
36           for (double i = 0; i < 100; i++) {
37               double duck=0.0;
38               double denominator = new Random().nextDouble();
39               int currOrChasingScore = new Random().nextInt();
40               // if(true) first innings    
41               double total = (denominator * currOrChasingScore) + currOrChasingScore;
42               duck = ((total) +total*(3.47 / 100));
43               assertEquals(duck, new DuckMath().calculateDl(denominator,currOrChasingScore,true));
44           }    
45       }
46  
47       //--------------------- TESTCASE NO 3 ---------------------------------//
48       public final void testCalculateDlFalse() {
49           for (double i = 0; i < 100; i++) {
50               double duck=0.0;
51               double denominator = new Random().nextDouble();
52               int currOrChasingScore = new Random().nextInt();
53               // if(false)  Second Innings    
54               double total = ((denominator) * currOrChasingScore);
55               duck = total +total*(3.47 / 100);
56           }    
57       }
58   }
created on June 3, 2010 5:51:40 PM CEST with CodeCover