use of com.android.tools.idea.ui.properties.core.IntValueProperty in project android by JetBrains.
the class IntExpressionsTest method testGreaterThanEqualExpression.
@Test
public void testGreaterThanEqualExpression() {
BoolValueProperty result = new BoolValueProperty();
IntValueProperty lhs = new IntValueProperty();
IntValueProperty rhs = new IntValueProperty();
BindingsManager bindings = new BindingsManager(INVOKE_IMMEDIATELY_STRATEGY);
bindings.bind(result, lhs.isGreaterThanEqualTo(rhs));
assertThat(result.get()).isTrue();
rhs.set(10);
assertThat(result.get()).isFalse();
lhs.set(10);
assertThat(result.get()).isTrue();
rhs.set(20);
assertThat(result.get()).isFalse();
}
use of com.android.tools.idea.ui.properties.core.IntValueProperty in project android by JetBrains.
the class ConstraintsTest method testPercent.
@Test
public void testPercent() throws Exception {
IntValueProperty percentValue = new IntValueProperty(-5);
percentValue.addConstraint(value -> Math.max(0, Math.min(100, value)));
assertThat(percentValue.get()).isEqualTo(0);
percentValue.set(-5);
assertThat(percentValue.get()).isEqualTo(0);
percentValue.set(105);
assertThat(percentValue.get()).isEqualTo(100);
percentValue.set(42);
assertThat(percentValue.get()).isEqualTo(42);
}
use of com.android.tools.idea.ui.properties.core.IntValueProperty in project android by JetBrains.
the class ConstraintsTest method testGreaterThanOne.
@Test
public void testGreaterThanOne() throws Exception {
IntValueProperty greaterThanOneValue = new IntValueProperty(5);
greaterThanOneValue.addConstraint(value -> Math.max(1, value));
assertThat(greaterThanOneValue.get()).isEqualTo(5);
greaterThanOneValue.set(-5);
assertThat(greaterThanOneValue.get()).isEqualTo(1);
greaterThanOneValue.set(105);
assertThat(greaterThanOneValue.get()).isEqualTo(105);
}
use of com.android.tools.idea.ui.properties.core.IntValueProperty in project android by JetBrains.
the class BindingsManagerTest method twoWayBindingsCanBeChained.
@Test
public void twoWayBindingsCanBeChained() {
BindingsManager bindings = new BindingsManager(INVOKE_IMMEDIATELY_STRATEGY);
IntValueProperty a = new IntValueProperty();
IntValueProperty b = new IntValueProperty();
IntValueProperty c = new IntValueProperty();
bindings.bindTwoWay(a, b);
bindings.bindTwoWay(b, c);
c.set(30);
assertThat(a.get()).isEqualTo(30);
assertThat(b.get()).isEqualTo(30);
assertThat(c.get()).isEqualTo(30);
b.set(-100);
assertThat(a.get()).isEqualTo(-100);
assertThat(b.get()).isEqualTo(-100);
assertThat(c.get()).isEqualTo(-100);
a.set(9);
assertThat(a.get()).isEqualTo(9);
assertThat(b.get()).isEqualTo(9);
assertThat(c.get()).isEqualTo(9);
}
use of com.android.tools.idea.ui.properties.core.IntValueProperty in project android by JetBrains.
the class BindingsManagerTest method oneWayBindingAffectedByTarget.
@Test
public void oneWayBindingAffectedByTarget() throws Exception {
BindingsManager bindings = new BindingsManager(INVOKE_IMMEDIATELY_STRATEGY);
IntValueProperty property1 = new IntValueProperty(10);
IntValueProperty property2 = new IntValueProperty(20);
bindings.bind(property1, property2);
assertThat(property1.get()).isEqualTo(20);
property1.set(30);
assertThat(property1.get()).isEqualTo(30);
assertThat(property2.get()).isEqualTo(20);
property2.set(40);
assertThat(property1.get()).isEqualTo(40);
}
Aggregations