public void ClearUlong_IndexOutOfRange_ThrowsException()
        {
            // ----------------------- Arrange -----------------------
            ulong v = 5ul;

            // -----------------------   Act   -----------------------
            // -----------------------  Assert -----------------------
            Assert.Throws <IndexOutOfRangeException>(() => v.Clear(100));
        }
        public void ClearUlong_ExpectedInput_AsExpected()
        {
            // ----------------------- Arrange -----------------------
            ulong v = 5ul;

            // -----------------------   Act   -----------------------
            v = v.Clear(2);
            // -----------------------  Assert -----------------------
            Assert.True(v == 1);
        }
コード例 #3
0
        public void hexRing_matches_kRingInternal()
        {
            for (int res = 0; res < 2; res++)
            {
                for (int i = 0; i < Constants.NUM_BASE_CELLS; i++)
                {
                    H3Index bc = 0;
                    H3Index.setH3Index(ref bc, 0, i, 0);
                    List <H3Index> bc_list = new List <H3Index> {
                        bc
                    };
                    int            childrenSz = H3Index.maxUncompactSize(ref bc_list, 1, res);
                    List <H3Index> children   = new ulong[childrenSz].Select(cell => new H3Index(cell)).ToList();
                    H3Index.uncompact(ref bc_list, 1, ref children, childrenSz, res);

                    for (int j = 0; j < childrenSz; j++)
                    {
                        if (children[j] == 0)
                        {
                            continue;
                        }

                        for (int k = 0; k < 3; k++)
                        {
                            int ringSz = k != 0
                                             ? 6 * k
                                             : 1;
                            int kSz = Algos.maxKringSize(k);


                            List <H3Index> ring   = new ulong[childrenSz].Select(cell => new H3Index(cell)).ToList();
                            int            failed = Algos.hexRing(children[j], k, ref ring);

                            if (failed != 0)
                            {
                                List <H3Index> internalNeighbors = new ulong[kSz].Select(cell => new H3Index(cell)).ToList();
                                List <int>     internalDistances = new int[kSz].Select(id => 0).ToList();
                                Algos._kRingInternal
                                (
                                    children[j], k, ref internalNeighbors,
                                    ref internalDistances, kSz, 0
                                );

                                int found         = 0;
                                int internalFound = 0;
                                for (int iRing = 0; iRing < ringSz; iRing++)
                                {
                                    if (ring[iRing] != 0)
                                    {
                                        found++;

                                        for (int iInternal = 0;
                                             iInternal < kSz;
                                             iInternal++)
                                        {
                                            if (internalNeighbors[iInternal] ==
                                                ring[iRing])
                                            {
                                                internalFound++;

                                                Assert.True
                                                (
                                                    internalDistances[iInternal] == k,
                                                    "Ring and internal agree on distance");

                                                break;
                                            }
                                        }
                                        Assert.True
                                            (found == internalFound,
                                            "Ring and internal implementations produce same output");
                                    }
                                }
                                internalNeighbors.Clear();
                                internalDistances.Clear();
                            }

                            ring.Clear();
                        }
                    }
                    children.Clear();
                }
            }
        }