Skip to content

Commit

Permalink
float and string tests
Browse files Browse the repository at this point in the history
  • Loading branch information
imurashka committed Aug 29, 2024
1 parent 5aa72ca commit d02e2e2
Showing 1 changed file with 178 additions and 6 deletions.
184 changes: 178 additions & 6 deletions Tests/BinaryPrefsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,21 @@ namespace Appegy.Tests.Storage
[TestFixture]
public class BinaryPrefsIntTests
{
[SetUp]
[SetUp, TearDown]
public void SetUp()
{
// Clear PlayerPrefs and BinaryPrefs before each test
PlayerPrefs.DeleteAll();
BinaryPrefs.DeleteAll();
}

#region Integer

[Test]
public void SetInt_ShouldStoreValueInBinaryStorage()
{
// Arrange
var key = "testInt";
var key = "key";
var value = 42;

// Act
Expand All @@ -34,7 +36,7 @@ public void SetInt_ShouldStoreValueInBinaryStorage()
public void GetInt_ShouldReturnDefaultValueIfKeyNotFound()
{
// Arrange
var key = "unknownInt";
var key = "unknownKey";
var defaultValue = 10;

// Act
Expand All @@ -48,7 +50,7 @@ public void GetInt_ShouldReturnDefaultValueIfKeyNotFound()
public void GetInt_ShouldReturnValueFromPlayerPrefsIfNotInBinaryStorage()
{
// Arrange
var key = "testInt";
var key = "key";
var playerPrefsValue = 100;

// Store value in PlayerPrefs only
Expand Down Expand Up @@ -82,7 +84,7 @@ public void GetInt_ShouldReturnDefaultValueIfKeyNotFoundInBothStorages()
public void SetInt_ShouldOverrideExistingValueInBinaryStorage()
{
// Arrange
var key = "testInt";
var key = "key";
var initialValue = 42;
var newValue = 84;

Expand All @@ -95,5 +97,175 @@ public void SetInt_ShouldOverrideExistingValueInBinaryStorage()
// Assert
BinaryPrefs.GetInt(key).Should().Be(newValue);
}

#endregion

#region Float

[Test]
public void SetFloat_ShouldStoreValueInBinaryStorage()
{
// Arrange
var key = "key";
var value = 42f;

// Act
BinaryPrefs.SetFloat(key, value);

// Assert
BinaryPrefs.GetFloat(key).Should().Be(value);
}

[Test]
public void GetFloat_ShouldReturnDefaultValueIfKeyNotFound()
{
// Arrange
var key = "unknownKey";
var defaultValue = 10f;

// Act
var result = BinaryPrefs.GetFloat(key, defaultValue);

// Assert
result.Should().Be(defaultValue);
}

[Test]
public void GetFloat_ShouldReturnValueFromPlayerPrefsIfNotInBinaryStorage()
{
// Arrange
var key = "key";
var playerPrefsValue = 100f;

// Store value in PlayerPrefs only
PlayerPrefs.SetFloat(key, playerPrefsValue);

// Act
var result = BinaryPrefs.GetFloat(key);

// Assert
result.Should().Be(playerPrefsValue);

// Verify that the value is now stored in BinaryStorage
BinaryPrefs.GetFloat(key).Should().Be(playerPrefsValue);
}

[Test]
public void GetFloat_ShouldReturnDefaultValueIfKeyNotFoundInBothStorages()
{
// Arrange
var key = "nonExistentKey";
var defaultValue = 20f;

// Act
var result = BinaryPrefs.GetFloat(key, defaultValue);

// Assert
result.Should().Be(defaultValue);
}

[Test]
public void SetFloat_ShouldOverrideExistingValueInBinaryStorage()
{
// Arrange
var key = "key";
var initialValue = 42f;
var newValue = 84f;

// Store initial value
BinaryPrefs.SetFloat(key, initialValue);

// Act
BinaryPrefs.SetFloat(key, newValue);

// Assert
BinaryPrefs.GetFloat(key).Should().Be(newValue);
}

#endregion

#region String

[Test]
public void SetString_ShouldStoreValueInBinaryStorage()
{
// Arrange
var key = "key";
var value = "42";

// Act
BinaryPrefs.SetString(key, value);

// Assert
BinaryPrefs.GetString(key).Should().Be(value);
}

[Test]
public void GetString_ShouldReturnDefaultValueIfKeyNotFound()
{
// Arrange
var key = "unknownKey";
var defaultValue = "10";

// Act
var result = BinaryPrefs.GetString(key, defaultValue);

// Assert
result.Should().Be(defaultValue);
}

[Test]
public void GetString_ShouldReturnValueFromPlayerPrefsIfNotInBinaryStorage()
{
// Arrange
var key = "key";
var playerPrefsValue = "100";

// Store value in PlayerPrefs only
PlayerPrefs.SetString(key, playerPrefsValue);

// Act
var result = BinaryPrefs.GetString(key);

// Assert
result.Should().Be(playerPrefsValue);

// Verify that the value is now stored in BinaryStorage
BinaryPrefs.GetString(key).Should().Be(playerPrefsValue);
}

[Test]
public void GetString_ShouldReturnDefaultValueIfKeyNotFoundInBothStorages()
{
// Arrange
var key = "nonExistentKey";
var defaultValue = "20";

// Act
var result = BinaryPrefs.GetString(key, defaultValue);

// Assert
result.Should().Be(defaultValue);
}

[Test]
public void SetString_ShouldOverrideExistingValueInBinaryStorage()
{
// Arrange
var key = "key";
var initialValue = "42";
var newValue = "84";

// Store initial value
BinaryPrefs.SetString(key, initialValue);

// Act
BinaryPrefs.SetString(key, newValue);

// Assert
BinaryPrefs.GetString(key).Should().Be(newValue);
}

#endregion
}
}
}

0 comments on commit d02e2e2

Please sign in to comment.