### Question:
OneHotEncodingFunc { @UserFunction("gds.alpha.ml.oneHotEncoding") @Description("RETURN gds.alpha.ml.oneHotEncoding(availableValues, selectedValues) - return a list of selected values in a one hot encoding format.") public List<Long> oneHotEncoding(@Name(value = "availableValues") List<Object> availableValues, @Name(value = "selectedValues") List<Object> selectedValues) { if (availableValues == null) { return LongStream.empty().boxed().collect(Collectors.toList()); } if (selectedValues == null) { return LongStream.range(0, availableValues.size()).map(index -> 0).boxed().collect(Collectors.toList()); } Set<Object> selectedValuesSet = new HashSet<>(selectedValues); Object[] availableValuesArray = availableValues.toArray(); return LongStream.range(0, availableValues.size()) .map(index -> selectedValuesSet.contains(availableValuesArray[(int) index]) ? 1L : 0L) .boxed() .collect(Collectors.toList()); }  @UserFunction("gds.alpha.ml.oneHotEncoding") @Description("RETURN gds.alpha.ml.oneHotEncoding(availableValues, selectedValues) - return a list of selected values in a one hot encoding format.") List<Long> oneHotEncoding(@Name(value = "availableValues") List<Object> availableValues,
                                     @Name(value = "selectedValues") List<Object> selectedValues);  }### Answer:
@Test void singleCategorySelected() { List<Object> values = asList("Italian", "Indian", "Chinese"); List<Object> selectedValues = Collections.singletonList("Italian"); assertEquals(asList(1L, 0L, 0L), new OneHotEncodingFunc().oneHotEncoding(values, selectedValues)); }
@Test void noCategoriesSelected() { List<Object> values = asList("Italian", "Indian", "Chinese"); List<Object> selectedValues = Collections.emptyList(); assertEquals(asList(0L, 0L, 0L), new OneHotEncodingFunc().oneHotEncoding(values, selectedValues)); }
@Test void moreThanOneSelected() { List<Object> values = asList("Italian", "Indian", "Chinese"); List<Object> selectedValues = Arrays.asList("Italian", "Chinese"); assertEquals(asList(1L, 0L, 1L), new OneHotEncodingFunc().oneHotEncoding(values, selectedValues)); }
@Test void allSelected() { List<Object> values = asList("Italian", "Indian", "Chinese"); List<Object> selectedValues = Arrays.asList("Italian", "Chinese", "Indian"); assertEquals(asList(1L, 1L, 1L), new OneHotEncodingFunc().oneHotEncoding(values, selectedValues)); }
@Test void nonExistentSelected() { List<Object> values = asList("Italian", "Indian", "Chinese"); List<Object> selectedValues = Collections.singletonList("British"); assertEquals(asList(0L, 0L, 0L), new OneHotEncodingFunc().oneHotEncoding(values, selectedValues)); }
@Test void oneNonExistentSelected() { List<Object> values = asList("Italian", "Indian", "Chinese"); List<Object> selectedValues = Arrays.asList("British", "Chinese"); assertEquals(asList(0L, 0L, 1L), new OneHotEncodingFunc().oneHotEncoding(values, selectedValues)); }
@Test void nullSelectedMeansNoneSelected() { List<Object> values = asList("Italian", "Indian", "Chinese"); assertEquals(asList(0L, 0L, 0L), new OneHotEncodingFunc().oneHotEncoding(values, null)); }
@Test void nullAvailableMeansEmptyArray() { assertEquals(Collections.emptyList(), new OneHotEncodingFunc().oneHotEncoding(null, null)); }