Bukkit-API  1.7.9-R0.2
The inofficial Bukkit-API
NoteTest.java
1 package org.bukkit;
2 
3 import static org.hamcrest.CoreMatchers.is;
4 import static org.hamcrest.CoreMatchers.nullValue;
5 import static org.junit.Assert.assertEquals;
6 import static org.junit.Assert.assertFalse;
7 import static org.junit.Assert.assertNotNull;
8 import static org.junit.Assert.assertThat;
9 import static org.junit.Assert.assertTrue;
10 import static org.junit.Assert.fail;
11 
12 import java.util.Collection;
13 
14 import org.junit.Test;
15 
16 import com.google.common.collect.Lists;
17 
18 public class NoteTest {
19  @Test
20  public void getToneByData() {
21  for (Note.Tone tone : Note.Tone.values()) {
22  assertThat(Note.Tone.getById(tone.getId()), is(tone));
23  }
24  }
25 
26  @Test
27  public void verifySharpedData() {
28  for (Note.Tone tone : Note.Tone.values()) {
29  if (!tone.isSharpable()) return;
30 
31  assertFalse(tone.isSharped(tone.getId(false)));
32  assertTrue(tone.isSharped(tone.getId(true)));
33  }
34  }
35 
36  @Test
37  public void verifyUnknownToneData() {
38  Collection<Byte> tones = Lists.newArrayList();
39  for (int i = Byte.MIN_VALUE; i <= Byte.MAX_VALUE; i++) {
40  tones.add((byte) i);
41  }
42 
43  for (Note.Tone tone : Note.Tone.values()) {
44  if (tone.isSharpable()) tones.remove(tone.getId(true));
45  tones.remove(tone.getId());
46  }
47 
48  for (Byte data : tones) {
49  assertThat(Note.Tone.getById(data), is(nullValue()));
50 
51  for (Note.Tone tone : Note.Tone.values()) {
52  try {
53  tone.isSharped(data);
54 
55  fail(data + " should throw IllegalArgumentException");
56  } catch (IllegalArgumentException e) {
57  assertNotNull(e);
58  }
59  }
60  }
61  }
62 
63  @Test(expected = IllegalArgumentException.class)
64  public void createNoteBelowMin() {
65  new Note((byte) -1);
66  }
67 
68  @Test(expected = IllegalArgumentException.class)
69  public void createNoteAboveMax() {
70  new Note((byte) 25);
71  }
72 
73  @Test(expected = IllegalArgumentException.class)
74  public void createNoteOctaveBelowMax() {
75  new Note((byte) -1, Note.Tone.A, true);
76  }
77 
78  @Test(expected = IllegalArgumentException.class)
79  public void createNoteOctaveAboveMax() {
80  new Note((byte) 3, Note.Tone.A, true);
81  }
82 
83  @Test
84  public void createNoteOctaveNonSharpable() {
85  Note note = new Note((byte) 0, Note.Tone.B, true);
86  assertFalse(note.isSharped());
87  assertThat(note.getTone(), is(Note.Tone.C));
88  }
89 
90  @Test
91  public void createNoteFlat() {
92  Note note = Note.flat(0, Note.Tone.D);
93  assertTrue(note.isSharped());
94  assertThat(note.getTone(), is(Note.Tone.C));
95  }
96 
97  @Test
98  public void createNoteFlatNonFlattenable() {
99  Note note = Note.flat(0, Note.Tone.C);
100  assertFalse(note.isSharped());
101  assertThat(note.getTone(), is(Note.Tone.B));
102  }
103 
104  @Test
105  public void testFlatWrapping() {
106  Note note = Note.flat(1, Note.Tone.G);
107  assertTrue(note.isSharped());
108  assertThat(note.getTone(), is(Note.Tone.F));
109  }
110 
111  @Test
112  public void testFlatWrapping2() {
113  Note note = new Note(1, Note.Tone.G, false).flattened();
114  assertTrue(note.isSharped());
115  assertThat(note.getTone(), is(Note.Tone.F));
116  }
117 
118  @Test
119  public void testSharpWrapping() {
120  Note note = new Note(1, Note.Tone.F, false).sharped();
121  assertTrue(note.isSharped());
122  assertThat(note.getTone(), is(Note.Tone.F));
123  assertEquals(note.getOctave(), 2);
124  }
125 
126  @Test(expected=IllegalArgumentException.class)
127  public void testSharpWrapping2() {
128  new Note(2, Note.Tone.F, true).sharped();
129  }
130 
131  @Test
132  public void testHighest() {
133  Note note = new Note(2, Note.Tone.F, true);
134  assertEquals(note.getId(), (byte)24);
135  }
136 
137  @Test
138  public void testLowest() {
139  Note note = new Note(0, Note.Tone.F, true);
140  assertEquals(note.getId(), (byte)0);
141  }
142 
143  @Test
144  public void doo() {
145  for (int i = 1; i <= 24; i++) {
146  Note note = new Note((byte) i);
147  int octave = note.getOctave();
148  Note.Tone tone = note.getTone();
149  boolean sharped = note.isSharped();
150 
151  Note newNote = new Note(octave, tone, sharped);
152  assertThat(newNote, is(note));
153  assertThat(newNote.getId(), is(note.getId()));
154  }
155  }
156 }
Note sharped()
Definition: Note.java:194
Note flattened()
Definition: Note.java:202
byte getId()
Definition: Note.java:214
static Note flat(int octave, Tone tone)
Definition: Note.java:161
int getOctave()
Definition: Note.java:223
static Tone getById(byte id)
Definition: Note.java:103
boolean isSharped()
Definition: Note.java:245
Tone getTone()
Definition: Note.java:236