arrays - Java Interface Testing and Coding Issues -
arrays - Java Interface Testing and Coding Issues -
i have been working on assignment past few hours , i'm stuck on lastly method histogram required assignment, have problems testing , code (i'm using netbeans).
the method should > histogram: takes positive number n indicating number of divisions in span of info divided, , returns array of integers of length n, each element of array contains count of elements fall division. example, if info (0.5, 1.2, 2.4, 9.8, 5.1, 10.5), span 10.0 (from 0.5 10.5). histogram(4) split range 4 segments: 0.5—3.0, 3.0—5.5, 5.5—8.0, , 8.0—10.5. inspecting data, see 3 values fall in first segment, 1 value in second, 0 values in third, , 2 values in fourth. therefore, returned value array of length 4 containing values (3, 1, 0, 2) in order. note sum of elements in returned array equal number of elements in info array.
here code:
@override public int[] histogram(int divisions) { int[] wide = new int[divisions]; double segment = span() / divisions; (int = 0; < data.length; i++) { if (data[i] <= (smallestelement() + segment)) { wide[0] = wide[0]+ 1; } else if (data[i] <= (smallestelement() + (2 * segment))) { wide[1] = wide[1]+ 1; } else if (data[i] <= (smallestelement() + (3 * segment))) { wide[2] = wide[2]+ 1; } else if (data[i] <= (smallestelement() + (4 * segment))) { wide[3] = wide[3]+ 1; } } homecoming wide; }
and here test of method above:
@test public void testhistogram() { double[] info = new double[3]; info = new double[]{0.5, 1.2, 2.4, 9.8, 5.1, 10.5}; int[] data2 = new int[4]; data2 = new int[]{3, 1, 0, 2}; doublearraystatisticaloutcomes = new doublearraystatisticaloutcomes(data); assertarrayequals(data2, a.histogram(4)); }
i utilize webcat submit work, , when submit assignment tells me there's tests missing method plus "histogram not accounting right number of elements", question issue occur in coding or missing something, same test.
thanks in advance.
you’re testing method values example. problem wrote method particular illustration in mind. happen if seek create histogram different length?
you should write more tests different info , different parameters, , check pass.
java arrays
Comments
Post a Comment