!7 lib 1010869 // decision trees lib 1004016 // slf4j lib 1004015 // slf4j simple import dt.DecisionTree; import dt.UnknownDecisionException; p { //DecisionTree tree = makeOutlookTree(); testOutlookOvercastApplyReturnsTrue(); testUnknownDecisionThrowsException(); print("OK"); } static void testOutlookOvercastApplyReturnsTrue() ctex { SS case1 = lithashmap( "Outlook", "Overcast", "Temperature", "Hot", "Humidity", "High", "Wind", "Strong"); assertTrue(makeOutlookTree().apply(case1)); } static void testUnknownDecisionThrowsException() { DecisionTree tree = new DecisionTree().setAttributes(new String[]{"Outlook"}) .setDecisions("Outlook", new String[]{"Sunny", "Overcast"}); try { tree.addExample(new String[]{"Rain"}, false); fail("no exception"); } catch (UnknownDecisionException e) { // ok } } static DecisionTree makeOutlookTree() { try { // example data from http://www.cise.ufl.edu/~ddd/cap6635/Fall-97/Short-papers/2.htm return new DecisionTree().setAttributes(new String[]{"Outlook", "Temperature", "Humidity", "Wind"}) .addExample( new String[]{"Sunny", "Hot", "High", "Weak"}, false) .addExample( new String[]{"Sunny", "Hot", "High", "Strong"}, false) .addExample( new String[]{"Overcast", "Hot", "High", "Weak"}, true) .addExample( new String[]{"Rain", "Mild", "High", "Weak"}, true) .addExample( new String[]{"Rain", "Cool", "Normal", "Weak"}, true) .addExample( new String[]{"Rain", "Cool", "Normal", "Strong"}, false) .addExample( new String[]{"Overcast", "Cool", "Normal", "Strong"}, true) .addExample( new String[]{"Sunny", "Mild", "High", "Weak"}, false) .addExample( new String[]{"Sunny", "Cool", "Normal", "Weak"}, true) .addExample( new String[]{"Rain", "Mild", "Normal", "Weak"}, true) .addExample( new String[]{"Sunny", "Mild", "Normal", "Strong"}, true) .addExample( new String[]{"Overcast", "Mild", "High", "Strong"}, true) .addExample( new String[]{"Overcast", "Hot", "Normal", "Weak"}, true) .addExample( new String[]{"Rain", "Mild", "High", "Strong"}, false); } catch (UnknownDecisionException e) { throw rethrow(e); } }