package com.veyndan.paper.reddit;

import android.support.annotation.NonNull;

import com.veyndan.paper.reddit.util.Node;

import org.junit.Test;

import io.reactivex.Observable;

/**
 * To work on unit tests, switch the Test Artifact in the Build Variants view.
 */
public class NodeTest {

    @Test
    public void descendantCount_unknownDescendantCount_isCorrect() {
        final Node<Void> node30 = setAsChildren();

        final Node<Void> node20 = setAsChildren(node30);
        final Node<Void> node21 = setAsChildren();
        final Node<Void> node22 = setAsChildren();

        final Node<Void> node10 = setAsChildren();
        final Node<Void> node11 = setAsChildren(node20, node21);
        final Node<Void> node12 = setAsChildren(node22);

        final Node<Void> node00 = setAsChildren(node10, node11, node12);

        node00.preOrderTraverse(0)
                .map(Node::getDescendantCount)
                .test()
                .assertValues(7, 0, 3, 1, 0, 0, 1, 0)
                .assertComplete();
    }

    @Test
    public void descendantCount_knownDescendantCount_isCorrect() {
        final Node<Void> node30 = setAsChildren();
        node30.setDescendantCount(0);

        final Node<Void> node20 = setAsChildren(node30);
        node20.setDescendantCount(1);

        final Node<Void> node21 = setAsChildren();
        node21.setDescendantCount(0);

        final Node<Void> node22 = setAsChildren();
        node22.setDescendantCount(0);

        final Node<Void> node10 = setAsChildren();
        node10.setDescendantCount(0);

        final Node<Void> node11 = setAsChildren(node20, node21);
        node11.setDescendantCount(3);

        final Node<Void> node12 = setAsChildren(node22);
        node12.setDescendantCount(1);

        final Node<Void> node00 = setAsChildren(node10, node11, node12);
        node00.setDescendantCount(7);

        node00.preOrderTraverse(0)
                .map(Node::getDescendantCount)
                .test()
                .assertValues(7, 0, 3, 1, 0, 0, 1, 0)
                .assertComplete();
    }

    @Test
    public void depth_isCorrect() {
        final Node<Void> node30 = setAsChildren();

        final Node<Void> node20 = setAsChildren(node30);
        final Node<Void> node21 = setAsChildren();
        final Node<Void> node22 = setAsChildren();

        final Node<Void> node10 = setAsChildren();
        final Node<Void> node11 = setAsChildren(node20, node21);
        final Node<Void> node12 = setAsChildren(node22);

        final Node<Void> node00 = setAsChildren(node10, node11, node12);

        node00.preOrderTraverse(0)
                .map(Node::getDepth)
                .test()
                .assertValues(0, 1, 1, 2, 3, 2, 1, 2)
                .assertComplete();
    }

    private static <T> Node<T> setAsChildren(final Node<T>... children) {
        return new Node<T>() {
            @NonNull
            @Override
            public Observable<Node<T>> getChildren() {
                return Observable.fromArray(children);
            }

            @NonNull
            @Override
            public Observable<Node<T>> asObservable() {
                return null;
            }
        };
    }
}

@@ -70,16 +70,60 @@
 NonNull;
+%0Aimport android.support.annotation.Nullable;
 %0A%0Aimport
@@ -2916,24 +2916,154 @@
 Node%3CT%3E() %7B%0A
+%0A            @Nullable%0A            @Override%0A            public Integer getDegree() %7B%0A                return null;%0A            %7D%0A%0A
             
@@ -3210,32 +3210,320 @@
 %0A            %7D%0A%0A
+            @NonNull%0A            @Override%0A            public Observable%3CBoolean%3E getTrigger() %7B%0A                return null;%0A            %7D%0A%0A            @NonNull%0A            @Override%0A            public Observable%3CNode%3CT%3E%3E asObservableImpl() %7B%0A                return null;%0A            %7D%0A%0A
             @Non

Fix tests