1// CHECKSTYLE:OFF Generated code
2/* This file is auto-generated from ParallaxIntTest.java.  DO NOT MODIFY. */
3
4/*
5 * Copyright (C) 2016 The Android Open Source Project
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 *      http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19package android.support.v17.leanback.widget;
20
21import static org.junit.Assert.assertEquals;
22import static org.junit.Assert.assertSame;
23
24import android.support.test.filters.SmallTest;
25import android.support.test.runner.AndroidJUnit4;
26
27import org.junit.Before;
28import org.junit.Test;
29import org.junit.runner.RunWith;
30
31@RunWith(AndroidJUnit4.class)
32@SmallTest
33public class ParallaxFloatTest {
34
35    Parallax<Parallax.FloatProperty> mSource;
36    int mScreenMax;
37
38    static void assertFloatEquals(float expected, float actual) {
39        org.junit.Assert.assertEquals((double) expected, (double) actual, 0.0001d);
40    }
41
42    @Before
43    public void setUp() throws Exception {
44        mSource = new Parallax<Parallax.FloatProperty>() {
45
46            @Override
47            public float getMaxValue() {
48                return mScreenMax;
49            }
50
51            @Override
52            public FloatProperty createProperty(String name, int index) {
53                return new FloatProperty(name, index);
54            }
55        };
56    }
57
58    @Test
59    public void testVariable() {
60        mScreenMax = 1080;
61        Parallax.FloatProperty var1 = mSource.addProperty("var1");
62        var1.setValue(mSource, 54);
63        assertFloatEquals((float) 54, var1.getValue(mSource));
64        assertEquals(var1.getName(), "var1");
65        var1.set(mSource, (float) 2000);
66        assertFloatEquals((float) 2000, var1.get(mSource).floatValue());
67    }
68
69    @Test
70    public void testFixedKeyValue() {
71        mScreenMax = 1080;
72        Parallax.FloatProperty var1 = mSource.addProperty("var1");
73
74        Parallax.FloatPropertyMarkerValue keyValue = (Parallax.FloatPropertyMarkerValue)
75                var1.atAbsolute(1000);
76        assertSame(keyValue.getProperty(), var1);
77        assertFloatEquals((float) 1000, keyValue.getMarkerValue(mSource));
78    }
79
80    @Test
81    public void testFractionOfKeyValue() {
82        mScreenMax = 1080;
83        Parallax.FloatProperty var1 = mSource.addProperty("var1");
84
85        Parallax.FloatPropertyMarkerValue keyValue = (Parallax.FloatPropertyMarkerValue)
86                var1.at(0, 0.5f);
87        assertSame(keyValue.getProperty(), var1);
88        assertFloatEquals((float) 540, keyValue.getMarkerValue(mSource));
89    }
90
91    @Test
92    public void testFixedKeyValueWithFraction() {
93        mScreenMax = 1080;
94        Parallax.FloatProperty var1 = mSource.addProperty("var1");
95
96        Parallax.FloatPropertyMarkerValue keyValue = (Parallax.FloatPropertyMarkerValue)
97                var1.at(-100, 0.5f);
98        assertSame(keyValue.getProperty(), var1);
99        assertFloatEquals((float) 440, keyValue.getMarkerValue(mSource));
100
101        Parallax.FloatPropertyMarkerValue keyValue2 = (Parallax.FloatPropertyMarkerValue)
102                var1.at(100, 0.5f);
103        assertSame(keyValue2.getProperty(), var1);
104        assertFloatEquals((float) 640, keyValue2.getMarkerValue(mSource));
105    }
106
107    @Test(expected = IllegalStateException.class)
108    public void testVerifyFloatPropertys_wrongOrder() {
109        Parallax.FloatProperty var1 = mSource.addProperty("var1");
110        Parallax.FloatProperty var2 = mSource.addProperty("var2");
111
112        var1.setValue(mSource, (float) 500);
113        var2.setValue(mSource, (float) 499);
114
115        mSource.verifyFloatProperties();
116    }
117
118    @Test(expected = IllegalStateException.class)
119    public void testVerifyFloatPropertysWrong_combination() {
120        Parallax.FloatProperty var1 = mSource.addProperty("var1");
121        Parallax.FloatProperty var2 = mSource.addProperty("var2");
122
123        var1.setValue(mSource, Parallax.FloatProperty.UNKNOWN_BEFORE);
124        var2.setValue(mSource, Parallax.FloatProperty.UNKNOWN_AFTER);
125
126        mSource.verifyFloatProperties();
127    }
128
129    @Test
130    public void testVerifyFloatPropertys_success() {
131        Parallax.FloatProperty var1 = mSource.addProperty("var1");
132        Parallax.FloatProperty var2 = mSource.addProperty("var2");
133
134        var1.setValue(mSource, (float) 499);
135        var2.setValue(mSource, (float) 500);
136
137        mSource.verifyFloatProperties();
138
139        var1.setValue(mSource, Parallax.FloatProperty.UNKNOWN_BEFORE);
140        var2.setValue(mSource, (float) 500);
141
142        mSource.verifyFloatProperties();
143
144        var1.setValue(mSource, (float) 499);
145        var2.setValue(mSource, Parallax.FloatProperty.UNKNOWN_AFTER);
146
147        mSource.verifyFloatProperties();
148    }
149}
150