Ejemplo n.º 1
0
func Test_Item(t *testing.T) {
	name := "test_item"
	template := database.NewTemplate(name)
	item := database.NewItem(template.GetId())

	testutils.Assert(item.GetName() == name, t, "Item didn't get created with correct name", name, item.GetName())
}
Ejemplo n.º 2
0
func Test_Menu(t *testing.T) {
	var Comm testutils.TestCommunicable
	Comm.ToRead = "a"

	called := false
	handled := false
	ExecMenu("Menu", &Comm, func(menu *Menu) {
		called = true

		menu.AddAction("a", "Apple", func() bool {
			handled = true
			return false
		})
	})

	testutils.Assert(called == true, t, "Failed to exec menu")
	testutils.Assert(handled == true, t, "Failed to handle menu action")
}
Ejemplo n.º 3
0
func Test_Room(t *testing.T) {
	fakeZoneId := bson.ObjectId("!2345")
	room := database.NewRoom(fakeZoneId, types.Coordinate{X: 0, Y: 0, Z: 0})

	testutils.Assert(room.GetZoneId() == fakeZoneId, t, "Room didn't have correct zone ID upon creation", fakeZoneId, room.GetZoneId())

	fakeZoneId2 := bson.ObjectId("11111")
	room.SetZoneId(fakeZoneId2)
	testutils.Assert(room.GetZoneId() == fakeZoneId2, t, "Call to room.SetZoneId() failed")

	directionList := make([]types.Direction, 10)
	directionCount := 10

	for i := 0; i < directionCount; i++ {
		directionList[i] = types.Direction(i)
	}

	for _, dir := range directionList {
		testutils.Assert(!room.HasExit(dir), t, "Room shouldn't have any exits enabled by default", dir)
		room.SetExitEnabled(dir, true)
		testutils.Assert(room.HasExit(dir), t, "Call to room.SetExitEnabled(true) failed")
		room.SetExitEnabled(dir, false)
		testutils.Assert(!room.HasExit(dir), t, "Call to room.SetExitEnabled(false) failed")
	}

	title := "Test Title"
	room.SetTitle(title)
	testutils.Assert(title == room.GetTitle(), t, "Call to room.SetTitle() failed", title, room.GetTitle())

	description := "This is a fake description"
	room.SetDescription(description)
	testutils.Assert(description == room.GetDescription(), t, "Call to room.SetDescription() failed", description, room.GetDescription())

	coord := types.Coordinate{X: 1, Y: 2, Z: 3}
	room.SetLocation(coord)
	testutils.Assert(coord == room.GetLocation(), t, "Call to room.SetLocation() failed", coord, room.GetLocation())
}
Ejemplo n.º 4
0
func Test_User(t *testing.T) {
	user := database.NewUser("testuser", "", false)

	if user.IsOnline() {
		t.Errorf("Newly created user shouldn't be online")
	}

	user.SetOnline(true)

	testutils.Assert(user.IsOnline(), t, "Call to SetOnline(true) failed")
	testutils.Assert(user.GetColorMode() == types.ColorModeNone, t, "Newly created user should have a color mode of None")

	user.SetColorMode(types.ColorModeLight)

	testutils.Assert(user.GetColorMode() == types.ColorModeLight, t, "Call to SetColorMode(types.ColorModeLight) failed")

	user.SetColorMode(types.ColorModeDark)

	testutils.Assert(user.GetColorMode() == types.ColorModeDark, t, "Call to SetColorMode(types.ColorModeDark) failed")

	pw := "password"
	user.SetPassword(pw)

	testutils.Assert(user.VerifyPassword(pw), t, "User password verification failed")

	width := 11
	height := 12
	user.SetWindowSize(width, height)

	testWidth, testHeight := user.GetWindowSize()

	testutils.Assert(testWidth == width && testHeight == height, t, "Call to SetWindowSize() failed")

	terminalType := "fake terminal type"
	user.SetTerminalType(terminalType)

	testutils.Assert(terminalType == user.GetTerminalType(), t, "Call to SetTerminalType() failed")
}
Ejemplo n.º 5
0
func Test_Zone(t *testing.T) {
	zoneName := "testzone"
	zone := database.NewZone(zoneName)

	testutils.Assert(zone.GetName() == zoneName, t, "Zone didn't have correct name upon creation", zoneName, zone.GetName())
}
Ejemplo n.º 6
0
func Test_PlayerCharacter(t *testing.T) {
	fakeId := bson.ObjectId("12345")
	character := database.NewPc("testcharacter", fakeId, fakeId)

	testutils.Assert(character.GetUserId() == fakeId, t, "Call to character.SetUser() failed", fakeId, character.GetUserId())
	testutils.Assert(!character.IsOnline(), t, "Player-Characters should be offline by default")

	character.SetOnline(true)

	testutils.Assert(character.IsOnline(), t, "Call to character.SetOnline(true) failed")

	character.SetRoomId(fakeId)

	testutils.Assert(character.GetRoomId() == fakeId, t, "Call to character.SetRoom() failed", fakeId, character.GetRoomId())

	cashAmount := 1234
	character.SetCash(cashAmount)

	testutils.Assert(character.GetCash() == cashAmount, t, "Call to character.GetCash() failed", cashAmount, character.GetCash())

	character.AddCash(cashAmount)

	testutils.Assert(character.GetCash() == cashAmount*2, t, "Call to character.AddCash() failed", cashAmount*2, character.GetCash())

	// conversation := "this is a fake conversation that is made up for the unit test"

	// character.SetConversation(conversation)

	// testutils.Assert(character.GetConversation() == conversation, t, "Call to character.SetConversation() failed")

	health := 123

	character.SetHealth(health)

	testutils.Assert(character.GetHealth() == health, t, "Call to character.SetHealth() failed")

	hitpoints := health - 10

	character.SetHitPoints(hitpoints)

	testutils.Assert(character.GetHitPoints() == hitpoints, t, "Call to character.SetHitPoints() failed")

	character.SetHitPoints(health + 10)

	testutils.Assert(character.GetHitPoints() == health, t, "Shouldn't be able to set a character's hitpoints to be greater than its maximum health", health, character.GetHitPoints())

	character.SetHealth(character.GetHealth() - 10)

	testutils.Assert(character.GetHitPoints() == character.GetHealth(), t, "Lowering health didn't lower the hitpoint count along with it", character.GetHitPoints(), character.GetHealth())

	character.SetHealth(100)
	character.SetHitPoints(100)

	hitAmount := 51
	character.Hit(hitAmount)

	testutils.Assert(character.GetHitPoints() == character.GetHealth()-hitAmount, t, "Call to character.Hit() failed", hitAmount, character.GetHitPoints())

	character.Heal(hitAmount)

	testutils.Assert(character.GetHitPoints() == character.GetHealth(), t, "Call to character.Heal() failed", hitAmount, character.GetHitPoints())
}