|
| 1 | +/* |
| 2 | + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one |
| 3 | + * or more contributor license agreements. Licensed under the Elastic License; |
| 4 | + * you may not use this file except in compliance with the Elastic License. |
| 5 | + */ |
| 6 | +package org.elasticsearch.xpack.core.ml.action; |
| 7 | + |
| 8 | +import org.elasticsearch.common.io.stream.NamedWriteableRegistry; |
| 9 | +import org.elasticsearch.common.io.stream.Writeable; |
| 10 | +import org.elasticsearch.test.AbstractWireSerializingTestCase; |
| 11 | +import org.elasticsearch.xpack.core.ml.action.EvaluateDataFrameAction.Response; |
| 12 | +import org.elasticsearch.xpack.core.ml.dataframe.evaluation.EvaluationMetricResult; |
| 13 | +import org.elasticsearch.xpack.core.ml.dataframe.evaluation.MlEvaluationNamedXContentProvider; |
| 14 | +import org.elasticsearch.xpack.core.ml.dataframe.evaluation.regression.MeanSquaredError; |
| 15 | +import org.elasticsearch.xpack.core.ml.dataframe.evaluation.regression.RSquared; |
| 16 | + |
| 17 | +import java.util.Arrays; |
| 18 | +import java.util.List; |
| 19 | + |
| 20 | +public class EvaluateDataFrameActionResponseTests extends AbstractWireSerializingTestCase<Response> { |
| 21 | + |
| 22 | + @Override |
| 23 | + protected NamedWriteableRegistry getNamedWriteableRegistry() { |
| 24 | + return new NamedWriteableRegistry(new MlEvaluationNamedXContentProvider().getNamedWriteables()); |
| 25 | + } |
| 26 | + |
| 27 | + @Override |
| 28 | + protected Response createTestInstance() { |
| 29 | + String evaluationName = randomAlphaOfLength(10); |
| 30 | + List<EvaluationMetricResult> metrics = |
| 31 | + Arrays.asList( |
| 32 | + new MeanSquaredError.Result(randomDouble()), |
| 33 | + new RSquared.Result(randomDouble())); |
| 34 | + int numMetrics = randomIntBetween(0, metrics.size()); |
| 35 | + return new Response(evaluationName, metrics.subList(0, numMetrics)); |
| 36 | + } |
| 37 | + |
| 38 | + @Override |
| 39 | + protected Writeable.Reader<Response> instanceReader() { |
| 40 | + return Response::new; |
| 41 | + } |
| 42 | +} |
0 commit comments