2018-11-06 23:25:35 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using FluentAssertions;
|
|
|
|
|
using PKHeX.Core;
|
|
|
|
|
using Xunit;
|
|
|
|
|
|
2019-03-19 02:33:56 +00:00
|
|
|
|
namespace PKHeX.Tests.PKM
|
2018-11-06 23:25:35 +00:00
|
|
|
|
{
|
2019-10-26 19:58:55 +00:00
|
|
|
|
public class StringTests
|
2018-11-06 23:25:35 +00:00
|
|
|
|
{
|
2019-10-26 19:58:55 +00:00
|
|
|
|
[Fact]
|
|
|
|
|
public void EncodesOTNameCorrectly()
|
2018-11-06 23:25:35 +00:00
|
|
|
|
{
|
2019-10-26 19:58:55 +00:00
|
|
|
|
const string name_fabian = "Fabian♂";
|
|
|
|
|
var pkm = new PK7 { OT_Name = name_fabian };
|
|
|
|
|
var byte_fabian = new byte[]
|
2018-11-06 23:25:35 +00:00
|
|
|
|
{
|
|
|
|
|
0x46, 0x00, // F
|
|
|
|
|
0x61, 0x00, // a
|
|
|
|
|
0x62, 0x00, // b
|
|
|
|
|
0x69, 0x00, // i
|
|
|
|
|
0x61, 0x00, // a
|
|
|
|
|
0x6E, 0x00, // n
|
|
|
|
|
0x8E, 0xE0, // ♂
|
|
|
|
|
0x00, 0x00, // \0 terminator
|
2019-10-26 19:58:55 +00:00
|
|
|
|
};
|
|
|
|
|
CheckStringGetSet(nameof(pkm.OT_Name), name_fabian, pkm.OT_Name, byte_fabian, pkm.OT_Trash);
|
|
|
|
|
}
|
2018-11-06 23:25:35 +00:00
|
|
|
|
|
2019-10-26 19:58:55 +00:00
|
|
|
|
[Fact]
|
|
|
|
|
public void EncodesNicknameCorrectly()
|
|
|
|
|
{
|
|
|
|
|
const string name_nidoran = "ニドラン♀";
|
|
|
|
|
var pkm = new PK7 { Nickname = name_nidoran };
|
|
|
|
|
var byte_nidoran = new byte[]
|
2018-11-06 23:25:35 +00:00
|
|
|
|
{
|
|
|
|
|
0xCB, 0x30, // ニ
|
|
|
|
|
0xC9, 0x30, // ド
|
|
|
|
|
0xE9, 0x30, // ラ
|
|
|
|
|
0xF3, 0x30, // ン
|
|
|
|
|
0x40, 0x26, // ♀
|
|
|
|
|
0x00, 0x00, // \0 terminator
|
2019-10-26 19:58:55 +00:00
|
|
|
|
};
|
|
|
|
|
CheckStringGetSet(nameof(pkm.Nickname), name_nidoran, pkm.Nickname, byte_nidoran, pkm.Nickname_Trash);
|
|
|
|
|
}
|
2018-11-06 23:25:35 +00:00
|
|
|
|
|
2019-10-26 19:58:55 +00:00
|
|
|
|
private static void CheckStringGetSet(string check, string instr, string outstr, byte[] indata,
|
|
|
|
|
byte[] outdata)
|
|
|
|
|
{
|
|
|
|
|
instr.Should().BeEquivalentTo(outstr);
|
2019-02-15 19:46:46 +00:00
|
|
|
|
|
2019-10-26 19:58:55 +00:00
|
|
|
|
outdata = outdata.Take(indata.Length).ToArray();
|
2018-11-06 23:25:35 +00:00
|
|
|
|
|
2019-10-26 19:58:55 +00:00
|
|
|
|
indata.SequenceEqual(outdata).Should()
|
|
|
|
|
.BeTrue($"expected {check} to set properly, instead got {string.Join(", ", outdata.Select(z => $"{z:X2}"))}");
|
2018-11-06 23:25:35 +00:00
|
|
|
|
}
|
2019-10-26 19:58:55 +00:00
|
|
|
|
}
|
2018-11-06 23:25:35 +00:00
|
|
|
|
|
2019-10-26 19:58:55 +00:00
|
|
|
|
public class MetDateTests
|
|
|
|
|
{
|
|
|
|
|
[Fact]
|
|
|
|
|
public void MetDateNullWhenDateComponentsAreAllZero()
|
2018-11-06 23:25:35 +00:00
|
|
|
|
{
|
2019-10-26 19:58:55 +00:00
|
|
|
|
var pk = new PK7
|
2018-11-06 23:25:35 +00:00
|
|
|
|
{
|
2019-10-26 19:58:55 +00:00
|
|
|
|
Met_Day = 0,
|
|
|
|
|
Met_Month = 0,
|
|
|
|
|
Met_Year = 0
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
pk.MetDate.HasValue.Should().BeFalse();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void MetDateReturnsCorrectDate()
|
|
|
|
|
{
|
|
|
|
|
var pk = new PK7
|
2018-11-06 23:25:35 +00:00
|
|
|
|
{
|
2019-10-26 19:58:55 +00:00
|
|
|
|
Met_Day = 10,
|
|
|
|
|
Met_Month = 8,
|
|
|
|
|
Met_Year = 16
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
pk.MetDate.GetValueOrDefault().Should().Be(new DateTime(2016, 8, 10).Date);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void MetDateCalculatesYear0Correctly()
|
|
|
|
|
{
|
|
|
|
|
var pk = new PK7
|
2018-11-06 23:25:35 +00:00
|
|
|
|
{
|
2019-10-26 19:58:55 +00:00
|
|
|
|
Met_Day = 1,
|
|
|
|
|
Met_Month = 1,
|
|
|
|
|
Met_Year = 0
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
pk.MetDate.GetValueOrDefault().Date.Year.Should().Be(2000);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void SettingToNullZerosComponents()
|
|
|
|
|
{
|
|
|
|
|
var pk = new PK7
|
2018-11-06 23:25:35 +00:00
|
|
|
|
{
|
2019-10-26 19:58:55 +00:00
|
|
|
|
Met_Day = 12,
|
|
|
|
|
Met_Month = 12,
|
|
|
|
|
Met_Year = 12
|
|
|
|
|
};
|
|
|
|
|
|
2020-12-22 07:37:07 +00:00
|
|
|
|
pk.Met_Day.Should().Be(12);
|
|
|
|
|
pk.Met_Month.Should().Be(12);
|
|
|
|
|
pk.Met_Year.Should().Be(12);
|
|
|
|
|
|
2019-10-26 19:58:55 +00:00
|
|
|
|
pk.MetDate = null;
|
|
|
|
|
|
|
|
|
|
pk.Met_Day.Should().Be(0);
|
|
|
|
|
pk.Met_Month.Should().Be(0);
|
|
|
|
|
pk.Met_Year.Should().Be(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void SettingMetDateSetsComponents()
|
|
|
|
|
{
|
|
|
|
|
var pk = new PK7
|
2018-11-06 23:25:35 +00:00
|
|
|
|
{
|
2019-10-26 19:58:55 +00:00
|
|
|
|
Met_Day = 12,
|
|
|
|
|
Met_Month = 12,
|
|
|
|
|
Met_Year = 12
|
|
|
|
|
};
|
|
|
|
|
|
2020-12-22 07:37:07 +00:00
|
|
|
|
pk.Met_Day.Should().Be(12);
|
|
|
|
|
pk.Met_Month.Should().Be(12);
|
|
|
|
|
pk.Met_Year.Should().Be(12);
|
|
|
|
|
|
2019-10-26 19:58:55 +00:00
|
|
|
|
pk.MetDate = new DateTime(2005, 5, 5);
|
|
|
|
|
|
|
|
|
|
pk.Met_Day.Should().Be(5);
|
|
|
|
|
pk.Met_Month.Should().Be(5);
|
|
|
|
|
pk.Met_Year.Should().Be(5);
|
2018-11-06 23:25:35 +00:00
|
|
|
|
}
|
2019-10-26 19:58:55 +00:00
|
|
|
|
}
|
2018-11-06 23:25:35 +00:00
|
|
|
|
|
2019-10-26 19:58:55 +00:00
|
|
|
|
public class EggMetDateTests
|
|
|
|
|
{
|
|
|
|
|
[Fact]
|
|
|
|
|
public void EggMetDateNullWhenDateComponentsAreAllZero()
|
2018-11-06 23:25:35 +00:00
|
|
|
|
{
|
2019-10-26 19:58:55 +00:00
|
|
|
|
var pk = new PK7
|
2018-11-06 23:25:35 +00:00
|
|
|
|
{
|
2019-10-26 19:58:55 +00:00
|
|
|
|
Egg_Day = 0,
|
|
|
|
|
Egg_Month = 0,
|
|
|
|
|
Egg_Year = 0
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
pk.EggMetDate.HasValue.Should().BeFalse();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void EggMetDateReturnsCorrectDate()
|
|
|
|
|
{
|
|
|
|
|
var pk = new PK7
|
2018-11-06 23:25:35 +00:00
|
|
|
|
{
|
2019-10-26 19:58:55 +00:00
|
|
|
|
Egg_Day = 10,
|
|
|
|
|
Egg_Month = 8,
|
|
|
|
|
Egg_Year = 16
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
pk.EggMetDate.GetValueOrDefault().Should().Be(new DateTime(2016, 8, 10).Date);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void EggMetDateCalculatesYear0Correctly()
|
|
|
|
|
{
|
|
|
|
|
var pk = new PK7
|
2018-11-06 23:25:35 +00:00
|
|
|
|
{
|
2019-10-26 19:58:55 +00:00
|
|
|
|
Egg_Day = 1,
|
|
|
|
|
Egg_Month = 1,
|
|
|
|
|
Egg_Year = 0
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
pk.EggMetDate.GetValueOrDefault().Date.Year.Should().Be(2000);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void SettingEggMetDateToNullZerosComponents()
|
|
|
|
|
{
|
|
|
|
|
var pk = new PK7
|
2018-11-06 23:25:35 +00:00
|
|
|
|
{
|
2019-10-26 19:58:55 +00:00
|
|
|
|
Egg_Day = 12,
|
|
|
|
|
Egg_Month = 12,
|
|
|
|
|
Egg_Year = 12
|
|
|
|
|
};
|
|
|
|
|
|
2020-12-22 07:37:07 +00:00
|
|
|
|
pk.Egg_Day.Should().Be(12);
|
|
|
|
|
pk.Egg_Month.Should().Be(12);
|
|
|
|
|
pk.Egg_Year.Should().Be(12);
|
|
|
|
|
|
2019-10-26 19:58:55 +00:00
|
|
|
|
pk.EggMetDate = null;
|
|
|
|
|
|
|
|
|
|
pk.Egg_Day.Should().Be(0);
|
|
|
|
|
pk.Egg_Month.Should().Be(0);
|
|
|
|
|
pk.Egg_Year.Should().Be(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void SettingEggMetDateSetsComponents()
|
|
|
|
|
{
|
|
|
|
|
var pk = new PK7
|
2018-11-06 23:25:35 +00:00
|
|
|
|
{
|
2019-10-26 19:58:55 +00:00
|
|
|
|
Egg_Day = 12,
|
|
|
|
|
Egg_Month = 12,
|
|
|
|
|
Egg_Year = 12
|
|
|
|
|
};
|
|
|
|
|
|
2020-12-22 07:37:07 +00:00
|
|
|
|
pk.Egg_Day.Should().Be(12);
|
|
|
|
|
pk.Egg_Month.Should().Be(12);
|
|
|
|
|
pk.Egg_Year.Should().Be(12);
|
|
|
|
|
|
2019-10-26 19:58:55 +00:00
|
|
|
|
pk.EggMetDate = new DateTime(2005, 5, 5);
|
|
|
|
|
|
|
|
|
|
pk.Egg_Day.Should().Be(5);
|
|
|
|
|
pk.Egg_Month.Should().Be(5);
|
|
|
|
|
pk.Egg_Year.Should().Be(5);
|
2018-11-06 23:25:35 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|