aboutsummaryrefslogtreecommitdiff
path: root/javatests/com/android/modules/expresslog/UniformOptionsTest.java
diff options
context:
space:
mode:
authorVova Sharaienko <sharaienko@google.com>2023-03-21 19:42:53 +0000
committerVova Sharaienko <sharaienko@google.com>2023-04-06 17:05:46 +0000
commitb9b201351dff32e4dc7f3b73d5240c6b33372a5f (patch)
tree2e3e0bdb71edae87bfbf810ccd039320f60d1fa5 /javatests/com/android/modules/expresslog/UniformOptionsTest.java
parentd4e5d67c9df0a853997dc9b38829f987a840c96b (diff)
downloadmodules-utils-b9b201351dff32e4dc7f3b73d5240c6b33372a5f.tar.gz
[TeX] Added telemetry express utility static libandroid-u-beta-1-gpl
- to be used by AdServices Bug: 271127104 Test: atest ExpressLogApisTests Change-Id: I914d6ac88e5b4445c51c09109a79ff828ada3e9b Merged-In: I914d6ac88e5b4445c51c09109a79ff828ada3e9b
Diffstat (limited to 'javatests/com/android/modules/expresslog/UniformOptionsTest.java')
-rw-r--r--javatests/com/android/modules/expresslog/UniformOptionsTest.java129
1 files changed, 129 insertions, 0 deletions
diff --git a/javatests/com/android/modules/expresslog/UniformOptionsTest.java b/javatests/com/android/modules/expresslog/UniformOptionsTest.java
new file mode 100644
index 0000000..3cc03ec
--- /dev/null
+++ b/javatests/com/android/modules/expresslog/UniformOptionsTest.java
@@ -0,0 +1,129 @@
+/*
+ * Copyright (C) 2023 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.modules.expresslog;
+
+import androidx.test.filters.SmallTest;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+@RunWith(JUnit4.class)
+@SmallTest
+public class UniformOptionsTest {
+ static {
+ System.loadLibrary("expresslog_test_jni");
+ }
+
+ private static final String TAG = UniformOptionsTest.class.getSimpleName();
+
+ @Test
+ public void testGetBinsCount() {
+ Histogram.UniformOptions options1 = new Histogram.UniformOptions(1, 100, 1000);
+ assertEquals(3, options1.getBinsCount());
+
+ Histogram.UniformOptions options10 = new Histogram.UniformOptions(10, 100, 1000);
+ assertEquals(12, options10.getBinsCount());
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testConstructZeroBinsCount() {
+ new Histogram.UniformOptions(0, 100, 1000);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testConstructNegativeBinsCount() {
+ new Histogram.UniformOptions(-1, 100, 1000);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testConstructMaxValueLessThanMinValue() {
+ new Histogram.UniformOptions(10, 1000, 100);
+ }
+
+ @Test
+ public void testBinIndexForRangeEqual1() {
+ Histogram.UniformOptions options = new Histogram.UniformOptions(10, 1, 11);
+ for (int i = 0, bins = options.getBinsCount(); i < bins; i++) {
+ assertEquals(i, options.getBinForSample(i));
+ }
+ }
+
+ @Test
+ public void testBinIndexForRangeEqual2() {
+ Histogram.UniformOptions options = new Histogram.UniformOptions(10, 1, 21);
+ for (int i = 0, bins = options.getBinsCount(); i < bins; i++) {
+ assertEquals(i, options.getBinForSample(i * 2));
+ assertEquals(i, options.getBinForSample(i * 2 - 1));
+ }
+ }
+
+ @Test
+ public void testBinIndexForRangeEqual5() {
+ Histogram.UniformOptions options = new Histogram.UniformOptions(2, 0, 10);
+ assertEquals(4, options.getBinsCount());
+ for (int i = 0; i < 2; i++) {
+ for (int sample = 0; sample < 5; sample++) {
+ assertEquals(i + 1, options.getBinForSample(i * 5 + sample));
+ }
+ }
+ }
+
+ @Test
+ public void testBinIndexForRangeEqual10() {
+ Histogram.UniformOptions options = new Histogram.UniformOptions(10, 1, 101);
+ assertEquals(0, options.getBinForSample(0));
+ assertEquals(options.getBinsCount() - 2, options.getBinForSample(100));
+ assertEquals(options.getBinsCount() - 1, options.getBinForSample(101));
+
+ final float binSize = (101 - 1) / 10f;
+ for (int i = 1, bins = options.getBinsCount() - 1; i < bins; i++) {
+ assertEquals(i, options.getBinForSample(i * binSize));
+ }
+ }
+
+ @Test
+ public void testBinIndexForRangeEqual90() {
+ final int binCount = 10;
+ final int minValue = 100;
+ final int maxValue = 100000;
+
+ Histogram.UniformOptions options = new Histogram.UniformOptions(binCount, minValue,
+ maxValue);
+
+ // logging underflow sample
+ assertEquals(0, options.getBinForSample(minValue - 1));
+
+ // logging overflow sample
+ assertEquals(binCount + 1, options.getBinForSample(maxValue));
+ assertEquals(binCount + 1, options.getBinForSample(maxValue + 1));
+
+ // logging min edge sample
+ assertEquals(1, options.getBinForSample(minValue));
+
+ // logging max edge sample
+ assertEquals(binCount, options.getBinForSample(maxValue - 1));
+
+ // logging single valid sample per bin
+ final int binSize = (maxValue - minValue) / binCount;
+
+ for (int i = 0; i < binCount; i++) {
+ assertEquals(i + 1, options.getBinForSample(minValue + binSize * i));
+ }
+ }
+}