Skip to content

Commit 7d34d18

Browse files
committed
which() does not suppport multivariate anymore.
1 parent 7ff517c commit 7d34d18

File tree

3 files changed

+12
-15
lines changed

3 files changed

+12
-15
lines changed

improveai/src/main/java/ai/improve/DecisionContext.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,8 @@ public Object which(Object... variants) {
186186
if(variants.length == 1) {
187187
if(variants[0] instanceof List) {
188188
return chooseFrom((List)variants[0]).get();
189-
} else if(variants[0] instanceof Map) {
190-
return optimize((Map)variants[0]).get();
191189
}
192-
throw new IllegalArgumentException("If only one argument, it must be a List or Map");
190+
throw new IllegalArgumentException("If only one argument, it must be a List.");
193191
}
194192

195193
return chooseFrom(Arrays.asList(variants)).get();

improveai/src/main/java/ai/improve/DecisionModel.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -352,13 +352,11 @@ public Decision optimize(Map<String, ?> variants) {
352352
* @param variants See chooseFrom().
353353
* When the only argument is a List, it's equivalent to calling
354354
* chooseFrom(variants).get();
355-
* When the only argument is a Map, it's equivalent to calling
356-
* optimize(variants).get();
357355
* When there are two or more arguments, all the arguments would form a
358356
* list and be passed to chooseFrom();
359357
* @return Returns the chosen variant
360-
* @throws IllegalArgumentException Thrown if variants is null or empty; or if there's only one
361-
* variant and it's not a List or Map.
358+
* @throws IllegalArgumentException Thrown if variants is null or empty; Thrown if there's only one
359+
* variant and it's not a List.
362360
* */
363361
public Object which(Object... variants) {
364362
return given(null).which(variants);
@@ -379,7 +377,7 @@ public <T> Decision<T> chooseFirst(List<T> variants) {
379377
* This is a short hand of chooseFirst().get().
380378
* @param variants See chooseFrom(). If only one argument, it must be a non-empty list.
381379
* @return If multiple arguments is passed to first(), the first argument would be returned;
382-
* If only one argument(a non-empty list), then the fist member of it would be returned.
380+
* If only one argument(a nonempty list), then the fist member of it would be returned.
383381
* @throws IllegalArgumentException Thrown if variants is null; Thrown if variants is empty;
384382
* Thrown if the there's only one argument and it's not a non-empty list.
385383
*/
@@ -398,7 +396,7 @@ public <T> Decision<T> chooseRandom(List<T> variants) {
398396

399397
/**
400398
* A shorthand of chooseRandom(variants).get()
401-
* @param variants See chooseFrom(). If only one argument, it must be a non-empty list. Expect
399+
* @param variants See chooseFrom(). If only one argument, it must be a nonempty list. Expect
402400
* at least one argument.
403401
* @return A random variant.
404402
* @throws IllegalArgumentException Thrown if variants is empty or null; Thrown if there's only

improveai/src/test/java/ai/improve/DecisionModelTest.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -751,12 +751,13 @@ public void testWhich_1_argument_map() {
751751
variants.put("color", Arrays.asList("#000000"));
752752
variants.put("size", 3);
753753
DecisionModel decisionModel = new DecisionModel("theme");
754-
Object best = decisionModel.which(variants);
755-
assertEquals(new HashMap<String, Object>(){{
756-
put("font", "Italic");
757-
put("color", "#000000");
758-
put("size", 3);
759-
}}, best);
754+
try {
755+
decisionModel.which(variants);
756+
} catch (IllegalArgumentException t) {
757+
t.printStackTrace();
758+
return ;
759+
}
760+
fail(DefaultFailMessage);
760761
}
761762

762763
@Test

0 commit comments

Comments
 (0)