mirror of
https://github.com/kwsch/PKHeX
synced 2024-12-03 17:29:13 +00:00
6182f889a6
Instead of looping, if the moveset is full and a new move is added, the game shifts all arr[1..] down one slot then adds the move at the end. Since we don't need to keep track of PP/PP Ups, we can just defer the shifting and do n % 4 rotations at the end instead of n rotations (one on each move added).
45 lines
1.4 KiB
C#
45 lines
1.4 KiB
C#
using System;
|
|
using FluentAssertions;
|
|
using Xunit;
|
|
using static System.Buffers.Binary.BinaryPrimitives;
|
|
|
|
namespace PKHeX.Core.Tests.Util;
|
|
|
|
public class FlagUtilTests
|
|
{
|
|
[Theory]
|
|
[InlineData(1, 0, 0)]
|
|
[InlineData(2, 0, 1)]
|
|
[InlineData(0x8000_0000, 3, 7)]
|
|
public void GetSetFlag(uint raw, int byteIndex, int bitIndex)
|
|
{
|
|
Span<byte> data = stackalloc byte[4];
|
|
WriteUInt32LittleEndian(data, raw);
|
|
var value = FlagUtil.GetFlag(data, byteIndex, bitIndex);
|
|
value.Should().Be(true);
|
|
|
|
Span<byte> copy = stackalloc byte[data.Length];
|
|
FlagUtil.SetFlag(copy, byteIndex, bitIndex, true);
|
|
data.SequenceEqual(copy).Should().BeTrue();
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData(0x7FFF_FFFE, 0, 0)]
|
|
public void ClearFlag(uint raw, int byteIndex, int bitIndex)
|
|
{
|
|
Span<byte> data = stackalloc byte[4];
|
|
WriteUInt32LittleEndian(data, raw);
|
|
var value = FlagUtil.GetFlag(data, byteIndex, bitIndex);
|
|
value.Should().Be(false);
|
|
|
|
// does nothing on empty
|
|
Span<byte> copy = stackalloc byte[data.Length];
|
|
FlagUtil.SetFlag(copy, byteIndex, bitIndex, false);
|
|
copy.IndexOfAnyExcept<byte>(0).Should().Be(-1);
|
|
|
|
// doesn't clear any other flag
|
|
data.CopyTo(copy);
|
|
FlagUtil.SetFlag(copy, byteIndex, bitIndex, false);
|
|
data.SequenceEqual(copy).Should().BeTrue();
|
|
}
|
|
}
|