summaryrefslogtreecommitdiff
path: root/Plugins/MonoGame.Extended/tests/MonoGame.Extended.Collisions.Tests/SpatialHashTests.cs
blob: 7c09a9e7417c4d58c2a219f0c0061e8457b1ac06 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using System.Collections.Generic;
using System.Linq;
using Xunit;

namespace MonoGame.Extended.Collisions.Tests;

public class SpatialHashTests
{
    private SpatialHash generateSpatialHash() => new SpatialHash(new Size2(64, 64));
    private readonly RectangleF RECT = new RectangleF(10, 10, 20, 20);

    [Fact]
    public void CollisionOneTrueTest()
    {
        var hash = generateSpatialHash();
        hash.Insert(new BasicActor()
        {
            Bounds = RECT,
        });
        var collisions = hash.Query(RECT);
        Assert.Equal(1, collisions.Count());
    }

    [Fact]
    public void CollisionTwoTest()
    {
        var hash = generateSpatialHash();
        hash.Insert(new BasicActor
        {
            Bounds = RECT,
        });
        hash.Insert(new BasicActor
        {
            Bounds = RECT,
        });
        var collisions = hash.Query(RECT);
        Assert.Equal(2, collisions.Count());
    }
}