-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add more AD params; add UT; fix license header
Signed-off-by: Yaliang Wu <ylwu@amazon.com>
- Loading branch information
Showing
8 changed files
with
199 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
common/src/test/java/org/opensearch/ml/common/parameter/AnomalyDetectionParamsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.ml.common.parameter; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.opensearch.common.io.stream.BytesStreamOutput; | ||
import org.opensearch.common.io.stream.StreamInput; | ||
import org.opensearch.common.xcontent.XContentParser; | ||
import org.opensearch.ml.common.TestHelper; | ||
|
||
import java.io.IOException; | ||
import java.util.function.Function; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
public class AnomalyDetectionParamsTest { | ||
|
||
AnomalyDetectionParams params; | ||
private Function<XContentParser, AnomalyDetectionParams> function = parser -> { | ||
try { | ||
return (AnomalyDetectionParams)AnomalyDetectionParams.parse(parser); | ||
} catch (IOException e) { | ||
throw new RuntimeException("failed to parse AnomalyDetectionParams", e); | ||
} | ||
}; | ||
|
||
@Before | ||
public void setUp() { | ||
params = AnomalyDetectionParams.builder() | ||
.kernelType(AnomalyDetectionParams.ADKernelType.POLY) | ||
.degree(2) | ||
.build(); | ||
} | ||
|
||
@Test | ||
public void parse_AnomalyDetectionParams() throws IOException { | ||
TestHelper.testParse(params, function); | ||
} | ||
|
||
@Test | ||
public void parse_Emptyparse_AnomalyDetectionParams() throws IOException { | ||
TestHelper.testParse(AnomalyDetectionParams.builder().build(), function); | ||
} | ||
|
||
@Test | ||
public void readInputStream_Success() throws IOException { | ||
readInputStream(params); | ||
} | ||
|
||
@Test | ||
public void readInputStream_Success_EmptyParams() throws IOException { | ||
readInputStream(AnomalyDetectionParams.builder().build()); | ||
} | ||
|
||
private void readInputStream(AnomalyDetectionParams params) throws IOException { | ||
BytesStreamOutput bytesStreamOutput = new BytesStreamOutput(); | ||
params.writeTo(bytesStreamOutput); | ||
|
||
StreamInput streamInput = bytesStreamOutput.bytes().streamInput(); | ||
AnomalyDetectionParams parsedParams = new AnomalyDetectionParams(streamInput); | ||
assertEquals(params, parsedParams); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,7 @@ | ||
# | ||
# Copyright OpenSearch Contributors | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
# The OpenSearch Contributors require contributions made to | ||
# this file be licensed under the Apache-2.0 license or a | ||
# compatible open source license. | ||
# | ||
# Modifications Copyright OpenSearch Contributors. See | ||
# GitHub history for details. | ||
# | ||
# | ||
|
||
opensearch_version = 1.3.0-SNAPSHOT | ||
opensearchBaseVersion = 1.3.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.